Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
config/initializers/delayed_job.rb with conditional mail delaying
# Conditionally delay outgoing mail
class DelayedMailerBase < ActionMailer::Base
class << self
def method_missing(method_symbol, *parameters)
# If this is "deliver_xx", maybe delay it; if we do, change
# its name so that we don't delay in the worker.
method_name = method_symbol.to_s
if matches_deliver_method?(method_name) and delaying_mail?
return self.send_later("delayed_#{method_name}".to_sym, *parameters)
end
# If this is a delayed name (meaning we're the worker),
# convert it back.
if match = matches_delayed_deliver_method?(method_name)
return super(match[1], *parameters)
end
super # Nothing funny - do the normal thing.
end
def respond_to?(method)
super or matches_deliver_method?(method) \
or matches_delayed_deliver_method?(method) \
end
def delaying_mail?
Rails.env.production?
end
private
def matches_deliver_method?(method_symbol) #:nodoc:
/^deliver_[_a-z]\w*/.match(method_symbol.to_s)
end
def matches_delayed_deliver_method?(method_symbol) #:nodoc:
/^delayed_(deliver.*)/.match(method_symbol.to_s)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.