# Scheduling in backgroundrb not working

**URL:** <https://www.ruby-forum.com/t/scheduling-in-backgroundrb-not-working/85525>\
**Category:** Rails\
**Created:** [February 14, 2007, 8:15am UTC](https://www.ruby-forum.com/t/scheduling-in-backgroundrb-not-working/85525 "2007-02-14T08:15:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ashwin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f08c70/32.png) [@ashwin](https://www.ruby-forum.com/u/ashwin)\
**Post date:** [February 14, 2007, 8:15am UTC](https://www.ruby-forum.com/t/scheduling-in-backgroundrb-not-working/85525/1 "2007-02-14T08:15:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ashwin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f08c70/32.png) [@ashwin](https://www.ruby-forum.com/u/ashwin)\
**Post date:** [February 14, 2007, 2:58pm UTC](https://www.ruby-forum.com/t/scheduling-in-backgroundrb-not-working/85525/2 "2007-02-14T14:58:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ashwin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f08c70/32.png) [@ashwin](https://www.ruby-forum.com/u/ashwin)\
**Post date:** [July 6, 2007, 9:54pm UTC](https://www.ruby-forum.com/t/scheduling-in-backgroundrb-not-working/85525/3 "2007-07-06T21:54:17Z")

</div>

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
