On Fri, Feb 08, 2013 at 02:13:18AM -0800, Michael Gaganov wrote:
>
> In the app I have several companies. Company has setting job_run_at
> (hour:0-24).
> So the job for each company should be run avery monday at given hour.
> It looks like:
>
> Company.all.each do |company|
> scheduler.cron "0 #{company.job_run_at} * * 1 #{company.timezone}", :tags
> => 'timesheet' do
> ...
> end
> end
Hello Michael,
welcome to the rufus mailing list.
Ouch, how about something like:
---8<---
scheduler.cron "0 1 * * 1", :tags => "timesheet" do
min = Time.now.min
Company.find_all(:job_run_at => min).each do
...
end
end
--->8---
So that it adapts changes to the company table...
> The questions are:
> 1) How can I restart the current company scheduler when job_run_at changed.
Well, you'd have to restart the process containing the scheduler, or simply
kill the jobs with the timesheet tag and schedule again.
I think my suggestion above would kill the need for those restarts...
> 2) I use unicorn. So if I use several workers doesn't this mean that
> several scheduler instances will be run too at the same time?
Sorry, I suggest you google for "unicorn rufus-scheduler" in this list or
globally and also read the unicorn manual. Rufus-scheduler is very dumb, it
just wants a main thread. Here on the list (and also on stack overflow iirc)
you'll find people coming up with exclusion schemes for such multiprocess
environments...
I hope it will help, best regards,
--
John Mettraux -
http://lambda.io/jmettraux