Pergunta

I've got a problem getting delayed_job script to work.

The delayed_job rake tasks "rake jobs:work" works fine in development and in production environment. But when I try to start it up with the script I get the following error:

user:~/rails1/current$ RAILS_ENV=production script/delayed_job start
/home/user/rails1/shared/bundle/ruby/1.9.1/gems/delayed_job-4.0.0/lib/delayed/command.rb:73:in `mkdir': File exists - /home/user/rails1/releases/20131218094848/tmp/pids (Errno::EEXIST)
    from /home/user/rails1/shared/bundle/ruby/1.9.1/gems/delayed_job-4.0.0/lib/delayed/command.rb:73:in `daemonize'
    from script/delayed_job:5:in `<main>'

As far as I know there is this code snippet in the delayed_job lib file command.rb (https://github.com/collectiveidea/delayed_job/blob/master/lib/delayed/command.rb)

def daemonize
      dir = @options[:pid_dir]
      Dir.mkdir(dir) unless File.exists?(dir)

      if @worker_count > 1 && @options[:identifier]
        raise ArgumentError, 'Cannot specify both --number-of-workers and --identifier'
      elsif @worker_count == 1 && @options[:identifier]
        process_name = "delayed_job.#{@options[:identifier]}"
        run_process(process_name, dir)
      else
        worker_count.times do |worker_index|
          process_name = worker_count == 1 ? "delayed_job" : "delayed_job.#{worker_index}"
          run_process(process_name, dir)
        end
      end
    end

which is causing my error.

As the error message says, the directory tmp/pids exists. But in the code there is an "unless" clause which says, that it shouldn't be created in case it exists. So why does the script tries to make the directory?

I've generated the script in development environment. Is it sensitive to the environment? This is the script:

#!/usr/bin/env ruby

require File.expand_path(File.join(File.dirname(__FILE__), '..', 'config', 'environment'))
require 'delayed/command'
Delayed::Command.new(ARGV).daemonize

Does anybody have a clue? just for your information: the daemons gem, which delayed_job needs, is in my gemfile.

UPDATE: I tried the start script now locally on my dev machine and there it works. But it still fails on my production machine. So the rake task "rake jobs:work" works on my dev machine and on the prodution server, but the script in script/delayed_job works only on my local dev machine.

Foi útil?

Solução

I found the solution. The tmp/pids was a symlink created through my hoster's capistrano recipe. It linked to a shared folder. But the corresponding directory wasn't there. Creating it resolved the problem!

Outras dicas

To add to this, you will want to keep tmp in your .gitignore, so just add an empty file to the directory and do a

git add tmp/pids/empty -f

to get the directory structure into your version control.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top