Scheduler and Rake Tasks

92 views
Skip to first unread message

April

unread,
Jul 12, 2009, 11:14:16 PM7/12/09
to Rufus Ruby
Hello,

I seem to be having trouble getting scheduler to run a rake task
repeatedly. It will run fine the first time, and the it won't run
again (the scheduler does run again, just the rake task seems not
to). The rake task seems to work just fine when I run it from the
console.

Any help would be much appreciated.

Thanks,
April

-------------------------
/config/initializers/rask_scheduler.rb

require 'rake'
load File.join( RAILS_ROOT, 'lib', 'tasks', 'emails.rake')
require 'rubygems'
require 'rufus/scheduler'

scheduler = Rufus::Scheduler.start_new

scheduler.every("1m") do
puts 'Scheduler is running'
Rake::Task["emails:send_queue"].invoke
end

--------------------------
/lib/tasks/email.rake

namespace :emails do

desc "Recurring email send"
task(:send_queue) do

puts 'send email'

end
end

John Mettraux

unread,
Jul 12, 2009, 11:50:49 PM7/12/09
to rufus...@googlegroups.com
On Mon, Jul 13, 2009 at 12:14 PM, April<uberg...@gmail.com> wrote:
>
> I seem to be having trouble getting scheduler to run a rake task
> repeatedly.  It will run fine the first time, and the it won't run
> again (the scheduler does run again, just the rake task seems not
> to).  The rake task seems to work just fine when I run it from the
> console.

Hello April,

ruby version ? rails version ? server (mongrel / thin / passenger) ?
rufus-scheduler version ? Are you running it along with EventMachine ?

No error message appearing on the console ?

Did you try things like specifying a custom exception handler ?

---8<---
def scheduler.handle_exception (job, exception)
puts "job #{job.job_id} caught exception '#{exception}'"
end
--->8---


Best regards,

--
John Mettraux - http://jmettraux.wordpress.com

Anna Knight

unread,
Jul 13, 2009, 12:10:32 AM7/13/09
to rufus...@googlegroups.com
Thanks for the quick response. 

Ruby version 1.8.6
Rails version 2.3.2
Server: mongrel (or webrick - I'm running instantrails for my development server)
Rufus-scheduler 2.0.1

No error message on the console.  I tried the custom exception handler you suggested, but since it seems there are no errors, nothing came up (at least that seems like the reasonable explanation to me).

Cheers,
April

John Mettraux

unread,
Jul 13, 2009, 12:14:15 AM7/13/09
to rufus...@googlegroups.com
On Mon, Jul 13, 2009 at 1:10 PM, Anna Knight<uberg...@gmail.com> wrote:
>
> Ruby version 1.8.6
> Rails version 2.3.2
> Server: mongrel (or webrick - I'm running instantrails for my development
> server)
> Rufus-scheduler 2.0.1
>
> No error message on the console.  I tried the custom exception handler you
> suggested, but since it seems there are no errors, nothing came up (at least
> that seems like the reasonable explanation to me).

Does the pattern "run once, then fail" always hold ?
Does the message "scheduler is running" only print once ?

Does running the rake task from the command line work ? Maybe you have
so sample output.

Anna Knight

unread,
Jul 13, 2009, 12:16:09 AM7/13/09
to rufus...@googlegroups.com
Yes, it does always hold, and "scheduler is running" only prints once.

Running from command line works every time.

Not sure what you mean by sample output?

John Mettraux

unread,
Jul 13, 2009, 12:22:02 AM7/13/09
to rufus...@googlegroups.com
On Mon, Jul 13, 2009 at 1:16 PM, Anna Knight<uberg...@gmail.com> wrote:
> Yes, it does always hold, and "scheduler is running" only prints once.
>
> Running from command line works every time.
>
> Not sure what you mean by sample output?

Just a STDOUT dump, but I have enough info from your answers, it's OK
for now, thanks.


> On Sun, Jul 12, 2009 at 11:14 PM, John Mettraux <jmet...@openwfe.org>
> wrote:
>>
>> On Mon, Jul 13, 2009 at 1:10 PM, Anna Knight<uberg...@gmail.com> wrote:
>> >
>> > Ruby version 1.8.6
>> > Rails version 2.3.2
>> > Server: mongrel (or webrick - I'm running instantrails for my
>> > development
>> > server)

Instantrails == windows ?
Does it work on a production equivalent environment ?

Could we say that it's not running on Windows but it's running on Linux ?

Reply all
Reply to author
Forward
0 new messages