lib/resque_scheduler.rb in sskirby-resque-scheduler-1.10.9 vs lib/resque_scheduler.rb in sskirby-resque-scheduler-1.10.13

- old
+ new

@@ -16,18 +16,25 @@ # "description" => "this thing works it"s butter off"}, # ...} # # :name can be anything and is used only to describe the scheduled job # :cron can be any cron scheduling string :job can be any resque job class + # :every can be used in lieu of :cron. see rufus-scheduler's 'every' usage for + # valid syntax. If :cron is present it will take precedence over :every. # :class must be a resque worker class # :args can be any yaml which will be converted to a ruby literal and passed # in a params. (optional) # :rails_envs is the list of envs where the job gets loaded. Envs are comma separated (optional) # :description is just that, a description of the job (optional). If params is # an array, each element in the array is passed as a separate param, # otherwise params is passed in as the only parameter to perform. def schedule=(schedule_hash) + if Resque::Scheduler.dynamic + schedule_hash.each do |name, job_spec| + set_schedule(name, job_spec) + end + end @schedule = schedule_hash end # Returns the schedule hash def schedule @@ -52,21 +59,27 @@ end end # create or update a schedule with the provided name and configuration def set_schedule(name, config) - redis.hset(:schedules, name, encode(config)) + existing_config = get_schedule(name) + unless existing_config && existing_config == config + redis.hset(:schedules, name, encode(config)) + redis.sadd(:schedules_changed, name) + end + config end # retrive the schedule configuration for the given name def get_schedule(name) decode(redis.hget(:schedules, name)) end # remove a given schedule by name def remove_schedule(name) redis.hdel(:schedules, name) + redis.sadd(:schedules_changed, name) end # This method is nearly identical to +enqueue+ only it also # takes a timestamp which will be used to schedule the job # for queueing. Until timestamp is in the past, the job will @@ -120,11 +133,11 @@ end end # Returns the next delayed queue timestamp # (don't call directly) - def next_delayed_timestamp - items = redis.zrangebyscore :delayed_queue_schedule, '-inf', Time.now.to_i, :limit => [0, 1] + def next_delayed_timestamp(at_time=nil) + items = redis.zrangebyscore :delayed_queue_schedule, '-inf', (at_time || Time.now).to_i, :limit => [0, 1] timestamp = items.nil? ? nil : Array(items).first timestamp.to_i unless timestamp.nil? end # Returns the next item to be processed for a given timestamp, nil if