background threads

Eric Wong normalperson at
Mon Jun 18 21:55:50 UTC 2012

Alexandre Riveira <alexandre at> wrote:
> Hello !
> I'm trying to put in background threads in Rainbows. I created a
> config/initializers/background_thread.rb, where I
> do
> # my background job
> end
> With that, I have problems to "reload" in rainbows

What kind of problems?

Is preload_app true or false?  (default is false)

preload_app being true will cause that background thread to get
started in the master process and not the workers.  You can
workaround it by starting th background thread in an after_fork
hook in the Rainbows!/unicorn config file:

> Thank you all for your help.

I'm often lazy when it comes to setting up hooks myself :x

So for background threads, I prefer to start it in the app stack
on the first request (use a mutex to protect against double-starts).
For rails, you can probably do it in a before_filter.

Raindrops::Watcher is a Rack app (no other framework, just rack)
which starts a background thread in the #call method:

	git clone git:// raindrops
	cat raindrops/lib/watcher.rb

More information about the rainbows-talk mailing list