Skip to content

Instantly share code, notes, and snippets.

@raecoo
Forked from Sutto/gist:943752
Created April 20, 2012 15:04
Show Gist options
  • Save raecoo/2429429 to your computer and use it in GitHub Desktop.
Save raecoo/2429429 to your computer and use it in GitHub Desktop.
Resque Daemon Controller
#!/usr/bin/env ruby
ENV['RAILS_ENV'] ||= 'development'
require File.expand_path('../../config/environment', __FILE__)
require 'daemon_spawn'
class ResqueWorkerDaemon < DaemonSpawn::Base
def start(args)
@worker = Resque::Worker.new('*') # Specify which queues this worker will process
@worker.verbose = 1 # Logging - can also set vverbose for 'very verbose'
@worker.work
end
def stop
@worker.try(:shutdown)
end
end
logs = Rails.root.join("log", "resque_workers.log").to_s
pids = Rails.root.join('tmp', 'pids', 'resque_workers.pid').to_s
ResqueWorkerDaemon.spawn!({
:processes => 2,
:log_file => logs,
:pid_file => pids,
:sync_log => true,
:working_dir => Rails.root,
:singleton => true
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment