module Resque::Scheduler::SchedulingExtensions
def all_schedules
def all_schedules non_persistent_schedules.merge(persistent_schedules) end
def fetch_schedule(name)
def fetch_schedule(name) schedule[name] end
def non_persistent_schedules
def non_persistent_schedules @non_persistent_schedules ||= {} end
def persistent_schedules
def persistent_schedules redis.hgetall(:persistent_schedules).tap do |h| h.each do |name, config| h[name] = decode(config) end end end
def prepare_schedules(schedule_hash)
def prepare_schedules(schedule_hash) prepared_hash = {} schedule_hash.each do |name, job_spec| job_spec = job_spec.dup unless job_spec.key?('class') || job_spec.key?(:class) job_spec['class'] = name end prepared_hash[name] = job_spec end prepared_hash end
def reload_schedule!
def reload_schedule! @schedule = all_schedules end
def remove_schedule(name, reload = true)
remove a given schedule by name
def remove_schedule(name, reload = true) non_persistent_schedules.delete(name) redis.hdel(:persistent_schedules, name) redis.sadd(:schedules_changed, [name]) reload_schedule! if reload end
def schedule
def schedule @schedule ||= all_schedules @schedule || {} end
def schedule=(schedule_hash)
param, otherwise params is passed in as the only parameter to
params is an array, each element in the array is passed as a separate
:description is just that, a description of the job (optional). If
comma separated (optional)
:rails_env is the list of envs where the job gets loaded. Envs are
passed in a params. (optional)
:args can be any yaml which will be converted to a ruby literal and
(hash key) will be used as :class.
:class must be a resque worker class. If it is missing, the job name
over :every.
usage for valid syntax. If :cron is present it will take precedence
:every can be used in lieu of :cron. see rufus-scheduler's 'every'
:cron can be any cron scheduling string
present in the new schedule, will be removed.
Any jobs that were in the old schedule, but are not
"MakeTea" is used both as job name and resque worker class.
is used implicitly as "class" argument - in the "MakeTea" example,
the scheduled job. If the "class" argument is missing, the key
Hash keys can be anything and are used to describe and reference
}
...
"description" => "this thing works it"s butter off" },
"args" => "work on this string",
"class" => "DoSomeWork",
"cron" => "5/* * * *",
"some_name" => {
"every" => "1m" },
"MakeTea" => {
{
Accepts a new schedule configuration of the form:
def schedule=(schedule_hash) @non_persistent_schedules = nil prepared_schedules = prepare_schedules(schedule_hash) prepared_schedules.each do |schedule, config| set_schedule(schedule, config, false) end # ensure only return the successfully saved data! reload_schedule! end
def set_schedule(name, config, reload = true)
:args => '/tmp/poop'})
:queue => 'high',
:every => '15mins',
Resque.set_schedule('some_job', {:class => 'SomeJob',
not constants.
Note: values for class and custom_job_class need to be strings,
Create or update a schedule with the provided name and configuration.
def set_schedule(name, config, reload = true) persist = config.delete(:persist) || config.delete('persist') if persist redis.hset(:persistent_schedules, name, encode(config)) else non_persistent_schedules[name] = decode(encode(config)) end redis.sadd(:schedules_changed, [name]) reload_schedule! if reload end