Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Prune stale Resque workers.
class ResqueStaleWorkerCleaner
SLOWEST_JOB = (ENV["SLOWEST_JOB"] || 30).to_i # minutes
def call
Resque.workers.each do |worker|
worker.unregister_worker if old_worker?(worker)
end
end
private
def old_worker?(worker)
worker.processing.empty? ||
Time.now - worker.processing["run_at"].to_time > 60 * SLOWEST_JOB
end
end
ResqueStaleWorkerCleaner.new.call
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.