# Backgroundrb and tasks

**URL:** <https://www.ruby-forum.com/t/backgroundrb-and-tasks/123752>\
**Category:** Rails\
**Created:** [December 20, 2007, 10:36am UTC](https://www.ruby-forum.com/t/backgroundrb-and-tasks/123752 "2007-12-20T10:36:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bublik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ecae2f/32.png) [@bublik](https://www.ruby-forum.com/u/bublik)\
**Post date:** [December 20, 2007, 10:36am UTC](https://www.ruby-forum.com/t/backgroundrb-and-tasks/123752/1 "2007-12-20T10:36:54Z")

</div>

Give me please example  
How i can send send email from Backgroundrb worker and  
How get access to my modele User

## my config

* * *

## port: “3333” timer\_sleep: 60 load\_rails: true environment: development rails\_env: development host: localhost database\_yml: config/database.yml acl: deny: all allow: localhost 127.0.0.1 order: deny,allow

## my worker

class PsWorker \< BackgrounDRb::Rails

repeat\_every 2.minutes  
first\_run Time.now

def do\_work(args)  
# This method is called in it’s own new thread when you  
# call new worker. args is set to :args

# logger.debug('DO\_WORK '+args.inspect)

```
Sende1.deliver_test()

```

end  
end

---

<div class="post-metadata">

**Author:** ![bublik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ecae2f/32.png) [@bublik](https://www.ruby-forum.com/u/bublik)\
**Post date:** [December 20, 2007, 11:48am UTC](https://www.ruby-forum.com/t/backgroundrb-and-tasks/123752/2 "2007-12-20T11:48:31Z")

</div>

On Thu, 2007-12-20 at 01:36 -0800, bublik wrote:

> environment: development  
> class PsWorker \< BackgrounDRb::Rails  
> end  
> You are running an old version of backgroundrb, please update your  
> plugin from here:

[http://svn.devjavu.com/backgroundrb/trunk/](http://svn.devjavu.com/backgroundrb/trunk/)

Full instructions can be found here:

[http://backgroundrb.rubyforge.org/](http://backgroundrb.rubyforge.org/)

So your worker with new plugin would look like:

class PsWorker \< BackgrounDRb::MetaWorker  
set\_worker\_name :ps\_worker

# gets called when worker is created

def create(args)  
deliver\_test\_mail()  
add\_periodic\_timer(2\*60) { deliver\_test\_mail }  
end

def deliver\_test\_mail  
Sende1.deliver\_test  
end  
end

Inside your workers, you have full access to your rails environment( and  
hence model and everything).

For more information, you can join backgroundrb mailing list on:

[http://rubyforge.org/mailman/listinfo/backgroundrb-devel](http://rubyforge.org/mailman/listinfo/backgroundrb-devel)

–  
Let them talk of their oriental summer climes of everlasting  
conservatories; give me the privilege of making my own summer with my  
own coals.

[http://gnufied.org](http://gnufied.org)
