Skip to content

Instantly share code, notes, and snippets.

@softwaregravy
Created July 31, 2011 22:41
Show Gist options
  • Save softwaregravy/1117306 to your computer and use it in GitHub Desktop.
Save softwaregravy/1117306 to your computer and use it in GitHub Desktop.
Pump custom values into hotoad
class CustomJob
def before(job)
Delayed::Context.set(:handler, job.handler)
Delayed::Context.set(:attempt, job.attempts + 1)
Delayed::Context.set(:last_error, job.last_error) if job.last_error
end
def after(job)
Delayed::Context.clear
end
def perform
#blah blah blah
end
end
module Delayed
module Context
def self.set(key, value)
Thread.current[:delayed_job_context] ||= Hash.new
Thread.current[:delayed_job_context][key] = value
end
def self.get_all
Thread.current[:delayed_job_context] || {}
end
def self.clear
Thread.current[:delayed_job_context] = Hash.new
end
end
end
module HoptoadNotifier
class Notice
alias _old_find_session_data find_session_data
def find_session_data
_old_find_session_data
self.session_data.merge!(Delayed::Context.get_all)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment