Skip to content

Instantly share code, notes, and snippets.

@hoan006
Last active August 29, 2015 14:00
Show Gist options
  • Save hoan006/11281124 to your computer and use it in GitHub Desktop.
Save hoan006/11281124 to your computer and use it in GitHub Desktop.
Resque stale jobs? Put a timeout for each possible one.
module CheckResqueJobTimeout
def self.included(klass)
klass.class_eval do
def self.perform_with_timeout(*args)
Timeout.timeout(120) do
perform_without_timeout(*args)
end
end
class << self
alias_method_chain :perform, :timeout
end
end
end
end
class SomeWorker
@queue = :some_worker
def self.perform
# some jobs that are stuck, such as uploading file to S3
end
# This module will make your job fail instead of hanging your worker process forever
include CheckResqueJobTimeout
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment