Solution to DelayedJob(DJ) gem server start problem

Solution to DelayedJob(DJ) gem server start problem
I had installed delayed_job gem 2.0.3, daemons gem but after staring DJ server it shows daemon started but actually process gets killed automatically.
I performed steps given by Kevin on google group and it worked like charm
Here are the steps:

1) sudo gem sources -a http://gems.github.com
2) sudo gem install alexvollmer-daemon-spawn
3) Move the old daemons delayed job script out of the way -> mv script/delayed_job script/delayed_job.daemons
4) Make this your new script/delayed_job: http://gist.github.com/104314

Try it out again making sure it writes to the tmp/pids directory ok.
My line looks like this:
RAILS_ENV=production script/delayed_job start
then to check (besides running ‘ps’), you can run this:
RAILS_ENV=production script/delayed_job status

15 thoughts on “Solution to DelayedJob(DJ) gem server start problem

  1. Hi, I need help to implement delayed jobs. I’m trying hard to do so, but still no luck. Following is the process i have used,

    1. Installed the required gems. i have also installed the plug-in
    2. Generated the script (delayed_job in script folder)
    3. I have created a simple controller abc.rb and a file xyz.rb in lib folder
    which includes the job that is to be executed.
    4. From the controller file I’m calling the class in the xyz.rb file in lib folder.
    The class in the xyz.rb file gets called but the perform method in that file
    does not get call.

    The job gets enqueued in the DB. I am using mongodb.
    After that, the job is processed and output is shown as follows,
    1 jobs processed at 0.1020 j/s, 0 failed …

    But in DB a new column gets added with following error.

    “{Job failed to load: uninitialized constant FirstJob. Handler: \”— !ruby/struct:FirstJob \\nmailing_id: 12\\n\”\u000a/home/sachin/.bundler/ruby/1.9.1/delayed_job-6c11015334aa/lib/delayed/backend/base.rb:81:in `rescue in payload_object’\\n/home/sachin/.bundler/ruby/1.9.1/delayed_job-6c11015334aa/lib/delayed/backend/base.rb:79:in `payload_object’\\n/home/sachin/.bundler/ruby/1.9.1/delayed_job-6c11015334aa/lib/delayed/backend/base.rb:87:in `invoke_job’\\n/home/sachin/.bundler/ruby/1.9.1/delayed_job-6c11015334aa/lib/delayed/worker.rb:120:in `block (2 levels) in run’\\n/usr/local/ruby/lib/ruby/1.9.1/timeout.rb:57:in `timeout’\\n/home/sachin/.bundler/ruby/1.9.1/delayed_job-6c11015334aa/lib/delayed/worker.rb:120:in `block in run’\\n/usr/local/ruby/lib/ruby/1.9.1/benchmark.rb:309:in `realtime’\\n/home/sachin/.bundler/ruby/1.9.1/delayed_job-6c11015334aa/lib/delayed/worker.rb:119:in `run’\\n/home/sachin/.bundler/ruby/1.9.1/delayed_job-6c11015334aa/lib/delayed/worker.rb:177:in `reserve_and_run_one_job’\\n/home/sachin/.bundler/ruby/1.9.1/delayed_job-6c11015334aa/lib/delayed/worker.rb:104:in `block in work_off’\\n/home/sachin/.bundler/ruby/1.9.1/delayed_job-6c11015334aa/lib/delayed/worker.rb:103:in `times’\\n/home/sachin/.bundler/ruby/1.9.1/delayed_job-6c11015334aa/lib/delayed/worker.rb:103:in `work_off’\\n/home/sachin/.bundler/ruby/1.9.1/delayed_job-6c11015334aa/lib/delayed/worker.rb:78:in `block (2 levels) in start’\\n/usr/local/ruby/lib/ruby/1.9.1/benchmark.rb:309:in `realtime’\\n/home/sachin/.bundler/ruby/1.9.1/delayed_job-6c11015334aa/lib/delayed/worker.rb:77:in `block in start’\\n/home/sachin/.bundler/ruby/1.9.1/delayed_job-6c11015334aa/lib/delayed/worker.rb:74:in `loop’\\n/home/sachin/.bundler/ruby/1.9.1/delayed_job-6c11015334aa/lib/delayed/worker.rb:74:in `start’\\n/home/sachin/projects/topspot/vendor/plugins/delayed_job/lib/delayed/command.rb:100:in `run’\\n/home/sachin/projects/topspot/vendor/plugins/delayed_job/lib/delayed/command.rb:79:in `block in run_process’\\n/usr/local/ruby/lib/ruby/gems/1.9.1/gems/daemons-1.1.0/lib/daemons/application.rb:250:in `call’\\n/usr/local/ruby/lib/ruby/gems/1.9.1/gems/daemons-1.1.0/lib/daemons/application.rb:250:in `block in start_proc’\\n/usr/local/ruby/lib/ruby/gems/1.9.1/gems/daemons-1.1.0/lib/daemons/daemonize.rb:199:in `call’\\n/usr/local/ruby/lib/ruby/gems/1.9.1/gems/daemons-1.1.0/lib/daemons/daemonize.rb:199:in `call_as_daemon’\\n/usr/local/ruby/lib/ruby/gems/1.9.1/gems/daemons-1.1.0/lib/daemons/application.rb:254:in `start_proc’\\n/usr/local/ruby/lib/ruby/gems/1.9.1/gems/daemons-1.1.0/lib/daemons/application.rb:294:in `start’\\n/usr/local/ruby/lib/ruby/gems/1.9.1/gems/daemons-1.1.0/lib/daemons/controller.rb:70:in `run’\\n/usr/local/ruby/lib/ruby/gems/1.9.1/gems/daemons-1.1.0/lib/daemons.rb:193:in `block in run_proc’\\n/usr/local/ruby/lib/ruby/gems/1.9.1/gems/daemons-1.1.0/lib/daemons/cmdline.rb:112:in `call’\\n/usr/local/ruby/lib/ruby/gems/1.9.1/gems/daemons-1.1.0/lib/daemons/cmdline.rb:112:in `catch_exceptions’\\n/usr/local/ruby/lib/ruby/gems/1.9.1/gems/daemons-1.1.0/lib/daemons.rb:192:in `run_proc’\\n/home/sachin/projects/topspot/vendor/plugins/delayed_job/lib/delayed/command.rb:78:in `run_process’\\n/home/sachin/projects/topspot/vendor/plugins/delayed_job/lib/delayed/command.rb:72:in `block in daemonize’\\n/home/sachin/projects/topspot/vendor/plugins/delayed_job/lib/delayed/command.rb:70:in `times’\\n/home/sachin/projects/topspot/vendor/plugins/delayed_job/lib/delayed/command.rb:70:in `daemonize’\\nscript/delayed_job:5:in `'”

    1. In my post above as i said that i’m calling xyz.rb in lib folder
      which includes the job that is to be executed. First time it gets called, and job gets enqued in the queue. After that when we run “rake jobs:work”, it searches for the xyz.rb in lib folder. But it fails to find it and hence error occurs. For that you need to add require ‘xyz’ in config/environment.rb file. It worked fine after that.

      1. @Sachin, @Scott,
        rake jobs:work is going to load the environment in a separate process space, its different from the web-server proces. So if you don’t load xyz.rb in the config/environment.rb file, rake will not pick it up.

        Usually, what I do, is that if they are delayed job worker, I require them in the config/initializers/delayed_job.rb file, where I also have the delayed job settings.

        This does not clutter the environment file.

  2. Hi, I’m using delayed job and its working fine.

    Now when i want to pass parameters to the delayed job like this
    Delayed::Job.enqueue(GaDelayedJob.new(par 1, par2 par 3),3,30.seconds.from_now)
    it gives an error
    “[DEPRECATION] Passing multiple arguments to `#enqueue` is deprecated. Pass a hash with :priority and :run_at.”

    After that i created a hash of the parameters and passed it but still got the same error.

    Please guide me

    1. Sachin,
      which version of delayed_job are you using? At such time, I strongly recommend opening the code and seeing what enqueue expects! 😉 It expects a hash with :payload_object which you missed out.

      def enqueue(*args)
      options = {
      :priority => Delayed::Worker.default_priority
      }

      if args.size == 1 && args.first.is_a?(Hash)
      options.merge!(args.first)
      else
      options[:payload_object] = args.shift
      options[:priority] = args.first || options[:priority]
      options[:run_at] = args[1]
      end

      1. Hi,
        The problem is solved. Actually i was using
        Delayed::Job.enqueue(GaDelayedJob.new(par 1, par2 par 3),3,30.seconds.from_now)

        and the only change i made was

        Delayed::Job.enqueue(GaDelayedJob.new(par 1, par2, par 3), :priority => ‘3’, :run_at => 30.seconds.from_now)

        and it worked fine after that.

        Thanks.

  3. Hi,

    I’m trying to implement GEM “whenever” from cron

    but getting following error

    rake aborted!
    no such file to load — rubygems
    /home/sachin/projects/fake_book/Rakefile:4:in `require’
    (See full trace by running task with –trace)
    rake aborted!
    no such file to load — rubygems
    /home/sachin/projects/fake_book/Rakefile:4:in `require’
    (See full trace by running task with –trace)

    Please help.

    1. Too less information. Considering you have posted on a delayedjob post, I suppose you are using delayed job — why do you need whenever?

      You can enqueue tasks in cron for delayed job like this:
      11 22 * * * /path/to/rails/root/script/runner -e production “Delayed::Job.enqueue SomeDelayedJob.new, 0”

      1. What i’m trying to do is….

        i have a xx no. of users. I am fetching data for all of them from some external data source. For that purpose, i tried to use “whenever” But now going with delayed job as “whenever” is not working for me.

        My scenario now is that, i have written code such that for all users one job will be enqueued using delayed job with different run at time with 1 minute interval between each job. when i fire rake jobs:work, worker gets started … process the first delayed job properly and for the rest enqueued jobs it says jobs processed, 0 failed …..BUT THE DATA IS NOT BEING PULLED , ITS BEING PULLED ONLY FOR THE FIRST JOB.

  4. Got the answer.

    Needed to use ——-> Rake::Task[“build”].reenable

    task :build_all do
    [ :debug, :release ].each do |t|
    $build_type = t
    Rake::Task[“build”].reenable
    Rake::Task[“build”].invoke
    end
    end

    1. Sachin,
      Maybe you should use Httpparty or typheous for parallel data fetch for users. So you can have one delayed_job which uses these simple tools to fetch information parallely for all users.

      Any particular reason for 1 minute delay between jobs? Is there an inter-dependency or is it to not overload your server?

      1. Reason for 1 minute delay between jobs, is not to overload the server.

        Thanks for the guidance

  5. I have a serious issue with delayed job , when I try to start it not starting any , I checked tmp/pids there is pid available for delayed job . Yesterday its was started fine suddenly its stopped working , when I try to get status using RAILS_ENV=development bin/delayed_job status i get the following message

    delayed_job: no instances running ,

    I checked db its not starting jobs , also I tried bundle exec rake jobs:work –trace the got the following error message

    rake aborted!
    SystemStackError: stack level too deep
    /home/.rvm/gems/ruby-2.1.5@vrcommand/gems/rake-10.4.2/lib/rake/task.rb:183
    Tasks: TOP => jobs:work

    not sure what happend . I am using delayedjob mongoid . can you please help me .

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.