delayed_job
1.23 KB
#!/usr/bin/env ruby
## This is the Noosfero delayed job controller script. It starts and stops the
# delayed job daemon, which is implemented in the DelayedJob plugin.
#
# The role of this script is to just start/stop the daemon, write a PID file,
# etc. The actual feed update logic is DelayedJob plugin.
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'config', 'environment'))
require 'daemons'
require 'delayed/command'
# based on https://groups.google.com/forum/#!topic/delayed_job/ZGMUFFppNgs
class Delayed::Worker
class ExceptionNotification < ActionMailer::Base
def mail error
environment = Environment.default
recipients NOOSFERO_CONF['exception_recipients']
from environment.contact_email
reply_to environment.contact_email
subject "[#{environment.name}] DelayedJob: #{error.message}"
body render(:text => error.backtrace.join("\n"))
end
end
def handle_failed_job_with_notification job, error
Delayed::Worker::ExceptionNotification.deliver_mail error if NOOSFERO_CONF['exception_recipients'].present?
handle_failed_job_without_notification job, error
end
alias_method_chain :handle_failed_job, :notification
end
Delayed::Command.new(ARGV).daemonize