Scheduling in backgroundrb not working


#1

Hi ,
How do i schedule a job that can send emails at intervals of time
using backgroundrb and rails

 For testing When i hit the controller i'm able send the emails.
 but that is not i intend to do .....

 I want to use backgroundrb and rails in which i'll schedule a job
 for every 5 minutes/ 1 minute or so..... to send an email

 But when i write .yml file as given by the
 http://backgroundrb.rubyforge.org/

 I'm unable to send emails ....... Infact my backgroundrb_server.log
 shows that scheduler is not even get triggered for every minute or

so

 I've no clue y the Scheduler is not working for every 1 minute or

so
… Any help is appreciated !!!

------------------------------------ backgroundrb.yml-----------------

:host: localhost
:port: 2000
:rails_env: development

my_scheduler:
:class: :mailman_worker
:job_key: :foo_name
:worker_method: :send_emails_to_people
:trigger_args: 0 */1 * * * * *

------------------------------------------my mailman_worker.rb --------

class MailmanWorker < BackgrounDRb::Worker::RailsBase

def do_work(args)
# This method is called in it’s own new thread when you
# call new worker. args is set to :args
# Replace this with your code
#
logger.info(‘I am in do work’)
end

def send_emails_to_people

@d_evals = User.find(:all,:conditions => ['id <= ?',3]

for lop in @d_users
  logger.info('I am in loop')
  @user = User.find(:first, :conditions => [ 'id = ?',lop.id])
  UserNotify.deliver_people_emails(@user)
end

end

end
MailmanWorker.register

-------------------------------------Controller code-----

class TestffController < ApplicationController

def a_pop
MiddleMan.new_worker(:class => :mailman_worker, :job_key =>
:foo_name)
worker = MiddleMan.worker(:foo_name)
worker.send_emails_to_people
worker.delete
end

end

--------------------------backgroundrb_server.log---------------------------------------------

I am in do work
20070213-20:15:22 (29661) I am in send_emails_to_people
20070213-20:15:22 (29661) I am in loop
20070213-20:16:04 (29668) Starting WorkerLogger
20070213-20:16:05 (29669) In ResultsWorker
20070213-20:16:07 (29669) I am in do work
20070213-20:16:07 (29669) I am in send_emails_to_evaluators
20070213-20:16:07 (29669) I am in loop
20070213-20:16:13 (29669) I am in loop
20070213-20:16:19 (29669) I am in loop

20070214-13:40:47 (1672) Starting WorkerLogger
20070214-13:40:48 (1673) In ResultsWorker
20070214-13:41:32 (1673) I am in do work
20070214-13:41:32 (1673) I am in send_emails_to_people
20070214-13:41:33 (1673) I am in loop
20070214-13:41:39 (1673) I am in loop
20070214-13:41:46 (1673) I am in loop

0070214-13:45:48 (1694) Starting WorkerLogger
20070214-13:45:49 (1695) In ResultsWorker

------ Ashwin Kumar


#2

Ashwin Kumar wrote:

:host: localhost
:port: 2000
:rails_env: development

my_scheduler:
:class: :mailman_worker
:job_key: :foo_name
:worker_method: :send_emails_to_people
:trigger_args: 0 */1 * * * * *

My case is not quite the same, but as I recall, I wasn’t able to make
*/1 work.

I use

:trigger_args: 0 * * * * * *

To fire the worker once a minute.

I’m also not certain that :worker_method works. I use:

:worker_method: :do_work

And call the “real” method from do_work.

def a_pop
MiddleMan.new_worker(:class => :mailman_worker, :job_key =>
:foo_name)
worker = MiddleMan.worker(:foo_name)
worker.send_emails_to_people
worker.delete
end

end

I don’t do this, just set up the config files and
(nohup) script/backgroundrb start

(The nohup is required if starting it remotely, e.g., from capistrano,
to keep it from quitting when you exit the shell you started it from.)

I hope this helps. I’ve been using backgroundrb happily for several
months for DB backup, session expiration, and periodic emails.

–Al Evans


#3

I can’t seem to get backgrounDRb up and running.

Here is my “backgroundrb.yml” file ******************************
autostart:
1:
job_key: mailing
class: mailman_worker
Here is “mailman_worker.rb” *************************************
class MailmanWorker < BackgrounDRb::Rails

repeat_every 5.minutes
first_run Time.now

def do_work(args)
## This will send all the emails in the queued_mails table
script/runner ‘MailQueue.process’ -e development #change
“production” to “development” or vice versa depending on what you’re
doing
kill()
end

end

It never seems to run. What do I need to do to get it to start up
automatically, and then run every 5 minutes?

Joe