Skip to content

Instantly share code, notes, and snippets.

@nileshbetter
Created December 7, 2010 07:18
Show Gist options
  • Save nileshbetter/731553 to your computer and use it in GitHub Desktop.
Save nileshbetter/731553 to your computer and use it in GitHub Desktop.
Dynamic Schedule Assignment doesn't work
Following schedule is set on Intialization. config/initializers
jt = ATask.find(:first)
dmt = BTask.find(:first)
Resque.schedule = {"ASchedule" => {
"cron" => "0 */#{jt.hours} * * *",
"class" => A,
"args" => "",
"description" => "Job for A"
},
"BSchedule" => {
"cron" => "#{dmt.run_at_mins} #{dmt.run_at_hrs} * * *",
"class" => B,
"args" => "",
"description" => "Job for B"
}
}
Above is a default schedule. Admin may want to change/update it. An interface is provided to Admin to do that. When Admin does the Schedule update, I execute following code in m controller
@b.run_at_hrs = params["hrs"].to_i
@b.run_at_mins = params["mns"].to_i
@b.save
Resque.schedule = {
"ASchedule" => {
"cron" => "0 */#{@task.hours} * * *",
"class" => A,
"args" => "",
"description" => "Job for A"
},
"BSchedule" => {
"cron" => "#{@b.run_at_mins} #{@b.run_at_hrs} * * *",
"class" => B,
"args" => "",
"description" => "Job for B"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment