Class/Module Index [+]

Quicksearch

Ruote::Exp::CronExpression

This expression executes its children expression according to a cron schedule or at a given frequency.

cron '15 4 * * sun' do # every sunday at 0415
  subprocess :ref => 'refill_the_acid_baths'
end

or

every '10m' do
  send_reminder # subprocess or participant
end

The 'tab' or 'interval' attributes may be used, this is a bit more verbose, but, for instance, in XML, it is quite necessary :

<cron tab="15 4 * * sun">
  <subprocess ref="refill_the_acid_baths" />
<cron>

Triggered children subprocesses are 'forgotten'. This implies they will never reply to the cron/every expression and they won't get cancelled when the cron/every expression gets cancelled (the cron/every schedule gets cancelled though, no new children will get cancelled).

"man 5 crontab" in the command line of your favourite unix system might help you with the semantics of the string expected by the cron expression.

an example use case

The cron/every expression appears often in scenarii like :

concurrence :count => 1 do

  participant 'operator'

  cron '0 9 * * 1-5' do # send a reminder every weekday at 0900
    notify 'operator'
  end
end

With a subprocess, this could become a bit more reusable :

Ruote.process_defintion :name => 'sample' do

  sequence do
    with_reminder :participant => 'operator1'
    with_reminder :participant => 'operator2'
  end

  define 'with_reminder' do
    concurrence :count => 1 do
      participant '${v:participant}'
      cron '0 9 * * 1-5' do # send a reminder every weekday at 0900
        notify '${v:participant}'
      end
    end
  end
end

Public Instance Methods

apply() click to toggle source
# File lib/ruote/exp/fe_cron.rb, line 94
def apply

  h.schedule = attribute(:tab) || attribute(:interval) || attribute_text
  h.job_id = nil

  reschedule
end
cancel(flavour) click to toggle source
# File lib/ruote/exp/fe_cron.rb, line 113
def cancel (flavour)

  @context.storage.delete_schedule(h.job_id)
  reply_to_parent(h.applied_workitem)
end
reply(workitem) click to toggle source
# File lib/ruote/exp/fe_cron.rb, line 102
def reply (workitem)

  launch_sub(
    "#{h.fei['expid']}_0",
    tree_children[0],
    :workitem => Ruote.fulldup(h.applied_workitem),
    :forget => true)

  reschedule
end
reschedule() click to toggle source

Note : this method has to be public.

# File lib/ruote/exp/fe_cron.rb, line 121
def reschedule

  h.job_id = @context.storage.put_schedule(
    'cron',
    h.fei,
    h.schedule,
    'action' => 'reply',
    'fei' => h.fei,
    'workitem' => h.applied_workitem)

  @context.storage.delete_schedule(h.job_id) if try_persist
    #
    # if the persist failed, immediately unschedule
    # the just scheduled job
    #
    # this is meant to cope with cases where one worker reschedules
    # while another just cancelled
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.