I searched up of google and found this thread. This is how I got my custom code executed on process_exit:
require 'god/contact'
class DelayedJobUnlockingNotifier < God::Contact
def notify(message, time, priority, category, host)
if pid = (message.match(/process (?<pid>.*) exited/) || {})['pid']
`bundle exec rake RAILS_ENV=#{RAILS_ENV} PID=#{pid} delayed_job:recover_locked_jobs`
applog(nil, :info, "delayed_job_unlocking_notifier: ran rake task to unlock locked jobs for PID: #{pid}")
end
rescue Object => e
applog(nil, :info, "delayed_job_unlocking_notifier: failed to unlock locked jobs for PID: #{pid}")
applog(nil, :debug, e.backtrace.join("\n"))
end
end