Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/usr/bin/env ruby
# -*- ruby -*-
require 'rubygems'
require 'daemon_spawn'
RAILS_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
class DelayedJobWorker < DaemonSpawn::Base
def start(args)
ENV['RAILS_ENV'] ||= args.first || 'development'
Dir.chdir RAILS_ROOT
require File.join('config', 'environment')
Delayed::Worker.new.start
end
def stop
system("kill `cat #{RAILS_ROOT}/tmp/pids/delayed_job.pid`")
end
end
DelayedJobWorker.spawn!(:log_file => File.join(RAILS_ROOT, "log", "delayed_job.log"),
:pid_file => File.join(RAILS_ROOT, 'tmp', 'pids', 'delayed_job.pid'),
:sync_log => true,
:working_dir => RAILS_ROOT)
@buntine

This comment has been minimized.

Copy link

commented Jan 12, 2012

Thanks.

Installed "daemon_spawn" from RubyGems and then required "daemon_spawn" instead of "daemon-spawn".

@akmathur

This comment has been minimized.

Copy link
Owner Author

commented Jan 12, 2012

@buntine: corrected. Thanks.

@rchampourlier

This comment has been minimized.

Copy link

commented Dec 19, 2012

Replaced

Dir.chdir RAILS_ROOT
require File.join('config', 'environment')

by

require File.join(RAILS_ROOT, 'config', 'environment')

to make it work for me (Rails 3.2.9, Ruby 1.9.3-p194).

Thanks a lot for this solution, it solves my issues with the original script/delayed_job without having to juggle with version of the daemons gem!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.