Skip to content

Instantly share code, notes, and snippets.

@Sutto
Created April 27, 2011 05:22
Show Gist options
  • Save Sutto/943752 to your computer and use it in GitHub Desktop.
Save Sutto/943752 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