Skip to content

Commit

Permalink
prevent cron from being kicked twice in multiple schedulers
Browse files Browse the repository at this point in the history
  • Loading branch information
Masatomo Nakano committed Feb 25, 2010
1 parent df72e6d commit 290a524
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
12 changes: 8 additions & 4 deletions lib/resque/scheduler.rb
Expand Up @@ -51,9 +51,13 @@ def load_schedule!
Resque.schedule.each do |name, config|
log! "Scheduling #{name} "
if !config['cron'].nil? && config['cron'].length > 0
rufus_scheduler.cron config['cron'] do
log! "queuing #{config['class']} (#{name})"
enqueue_from_config(config)
rufus_scheduler.cron config['cron'] do |c|
if Resque.cron_not_done?(name, c.last)
log! "queuing #{config['class']} (#{name})"
enqueue_from_config(config)
else
log! "cron already done in other shcduler for #{config['class']} (#{name}) - skipping"
end
end
else
log! "no cron found for #{config['class']} (#{name}) - skipping"
Expand Down Expand Up @@ -135,4 +139,4 @@ def log(msg)

end

end
end
5 changes: 4 additions & 1 deletion lib/resque_scheduler.rb
Expand Up @@ -109,9 +109,12 @@ def next_item_for_timestamp(timestamp)
item
end

def cron_not_done?(name, timestamp)
redis.getset("cron_#{name}", timestamp.to_i).to_s != timestamp.to_i.to_s
end
end

Resque.extend ResqueScheduler
Resque::Server.class_eval do
include ResqueScheduler::Server
end
end

0 comments on commit 290a524

Please sign in to comment.