views:

406

answers:

3

I am currently using a site5 server and would like rake jobs:work pretty much running all the time. I currently cannot send out the jobs unless i'm logged into the server. I hope that someone out there can help me with this. Had alot of trouble with ar_mailer and the whenever gem ... but have about another 5 gems working perfectly within my rails app.

can someone shed some light on a solution for this please? greatly appreciated. (installed delayed_job as a plugin)

A: 

If you are using capistrano, start delayed_job when your app is deployed. Add this to your deploy recipe file.

require 'delayed/recipes'
after "deploy:stop",        "delayed_job:stop"
after "deploy:start",       "delayed_job:start"
after "deploy:update_code", "delayed_job:stop"
after "deploy:restart",     "delayed_job:start"
Jonathan Julian
Not using capistrano unfortunately. And when i run script/delayed_job start or script/delayed_job restart no error is thrown, however the worker does not run in the background. I still have the feeling i'm missing something.Also, when I run script/delayed_job run i get "uninitialized constant Delayed::Backend::ActiveRecord::Base"there has to be something simple I'm missing.Thanks for the attempt though.
Matenia Rossides
Try the http://github.com/collectiveidea/delayed_job fork. It's under heavy and active development to make it more robust.
Jonathan Julian
Thanks again Jonathan, I am using this one and not the tobi one for that exact reason. It processes the delayed_job and puts it in the table, the only problem I have is that I want to have the worker running all the time without having to keep calling "rake jobs:work". I can set the delay in the config initializer thats not the problem, even with setting up a cron job to do this, for some reason it just doesnt want to work... :(
Matenia Rossides
With cron you are only running jobs at certain intervals; you say you want it running all the time. You could run it under `god` which will restart it if it ever dies. See http://jetpackweb.com/blog/tags/delayed_job/
Jonathan Julian
A: 

OK I have a workaround for this, it's the best I can do but it works to some degree ... I made use of CRON jobs and a custom script/jobrunner file.

I created the jobrunner script located at script/jobrunner which contains the following

#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/environment'
Delayed::Worker.new.start

Then in a cron job i made it run that file.

In the cron report i still get a few errors, but the jobs run and i'm happy with that!

The cron job is running every hour on the 50th minute for example, and it goes through all the delayed_jobs in the table and processes them. This is the next best workaround solution that i have found to my problem. hope this helps someone out in the future.

Going to see what other scripts i can conjure up for daily/weekly tasks.

Matenia Rossides
+1  A: 

Delayed job comes with a script for starting itself in the background and logging to log/delayed_job.log. You can start a daemonized delayed_job running in development mode like this:

RAILS_ENV=development script/delayed_job start
Michael Hale