Created
November 7, 2010 21:06
-
-
Save jimsynz/666841 to your computer and use it in GitHub Desktop.
Daemonfile for running Delayed::Worker instances.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# How often daemonizer's monitor process | |
# checks the status of workers. | |
poll_period 5 | |
pool :delayed_workers do | |
# Attempt to intuit the number of CPU cores on this machine and start | |
# a corresponding number of workers. Should work on any modern Linux | |
# (>= 2.6 kernel). | |
if File.exist? "/sys/devices/system/cpu/online" | |
total_cpus = 1 | |
cpu_pattern = File.read("/sys/devices/system/cpu/online").chomp | |
cpu_pattern.split(',').each do |range| | |
range = eval(range.gsub('-','..')) | |
total_cpus += range.end - range.begin | |
end | |
workers total_cpus | |
# If there is an environment variable, use that | |
elsif i = ENV['CONCURRENCY_LEVEL'] | |
workers i.to_i | |
# Otherwise default to two. You may want to change this. | |
else | |
workers 2 | |
end | |
log_file = "log/delayed_worker_monitor.log" | |
pid_file 'tmp/pids/delayed_worker_monitor.pid' | |
not_cow_friendly | |
prepare do |block| | |
# Load the rails environment inside this worker process. | |
require File.join(Daemonizer.root, '/config/environment') | |
block.call | |
end | |
start do |worker_id, workers_count| | |
# Configure the logger for this instance | |
Delayed::Worker.logger = ActiveSupport::BufferedLogger.new(File.join(Daemonizer.root, "log/delayed_worker_#{worker_id}.log")) | |
# Create a worker instance. | |
worker = Delayed::Worker.new | |
# Start it. | |
worker.start | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment