1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Rename remaining :in / :at to :wait / :wait_until

This commit is contained in:
Cristian Bica 2014-09-04 08:08:06 +03:00
parent 1e237b4e44
commit 15ddf60e05
4 changed files with 22 additions and 25 deletions

View file

@ -39,13 +39,13 @@ module ActionMailer
# and +raise_delivery_errors+, so use with caution.
#
# Notifier.welcome(User.first).deliver_later!
# Notifier.welcome(User.first).deliver_later!(in: 1.hour)
# Notifier.welcome(User.first).deliver_later!(at: 10.hours.from_now)
# Notifier.welcome(User.first).deliver_later!(wait: 1.hour)
# Notifier.welcome(User.first).deliver_later!(wait_until: 10.hours.from_now)
#
# Options:
#
# * <tt>:in</tt> - Enqueue the email to be delivered with a delay
# * <tt>:at</tt> - Enqueue the email to be delivered at (after) a specific date / time
# * <tt>:wait</tt> - Enqueue the email to be delivered with a delay
# * <tt>:wait_until</tt> - Enqueue the email to be delivered at (after) a specific date / time
def deliver_later!(options={})
enqueue_delivery :deliver_now!, options
end
@ -54,13 +54,13 @@ module ActionMailer
# job runs it will send the email using +deliver_now+.
#
# Notifier.welcome(User.first).deliver_later
# Notifier.welcome(User.first).deliver_later(in: 1.hour)
# Notifier.welcome(User.first).deliver_later(at: 10.hours.from_now)
# Notifier.welcome(User.first).deliver_later(wait: 1.hour)
# Notifier.welcome(User.first).deliver_later(wait_until: 10.hours.from_now)
#
# Options:
#
# * <tt>:in</tt> - Enqueue the email to be delivered with a delay
# * <tt>:at</tt> - Enqueue the email to be delivered at (after) a specific date / time
# * <tt>:wait</tt> - Enqueue the email to be delivered with a delay
# * <tt>:wait_until</tt> - Enqueue the email to be delivered at (after) a specific date / time
def deliver_later(options={})
enqueue_delivery :deliver_now, options
end
@ -98,10 +98,7 @@ module ActionMailer
def enqueue_delivery(delivery_method, options={})
args = @mailer.name, @mail_method.to_s, delivery_method.to_s, *@args
set_options = {}
set_options[:wait_until] = options[:at] if options[:at]
set_options[:wait] = options[:in] if options[:in]
ActionMailer::DeliveryJob.set(set_options).perform_later(*args)
ActionMailer::DeliveryJob.set(options).perform_later(*args)
end
end
end

View file

@ -87,15 +87,17 @@ class MessageDeliveryTest < ActiveSupport::TestCase
end
test 'should enqueue a delivery with a delay' do
assert_performed_with(job: ActionMailer::DeliveryJob, args: ['DelayedMailer', 'test_message', 'deliver_now', 1, 2, 3]) do
@mail.deliver_later in: 600.seconds
travel_to Time.new(2004, 11, 24, 01, 04, 44) do
assert_performed_with(job: ActionMailer::DeliveryJob, at: Time.current.to_f+600.seconds, args: ['DelayedMailer', 'test_message', 'deliver_now', 1, 2, 3]) do
@mail.deliver_later wait: 600.seconds
end
end
end
test 'should enqueue a delivery at a specific time' do
later_time = Time.now.to_f + 3600
assert_performed_with(job: ActionMailer::DeliveryJob, at: later_time, args: ['DelayedMailer', 'test_message', 'deliver_now', 1, 2, 3]) do
@mail.deliver_later at: later_time
@mail.deliver_later wait_until: later_time
end
end

View file

@ -2,8 +2,6 @@ module ActiveJob
class ConfiguredJob #:nodoc:
def initialize(job_class, options={})
@options = options
@options[:in] = @options.delete(:wait) if @options[:wait]
@options[:at] = @options.delete(:wait_until) if @options[:wait_until]
@job_class = job_class
end

View file

@ -27,8 +27,8 @@ module ActiveJob
# you can ask Active Job to retry performing your job.
#
# ==== Options
# * <tt>:in</tt> - Enqueues the job with the specified delay
# * <tt>:at</tt> - Enqueues the job at the time specified
# * <tt>:wait</tt> - Enqueues the job with the specified delay
# * <tt>:wait_until</tt> - Enqueues the job at the time specified
# * <tt>:queue</tt> - Enqueues the job on the specified queue
#
# ==== Examples
@ -48,19 +48,19 @@ module ActiveJob
# Equeue the job to be performed by the queue adapter.
#
# ==== Options
# * <tt>:in</tt> - Enqueues the job with the specified delay
# * <tt>:at</tt> - Enqueues the job at the time specified
# * <tt>:wait</tt> - Enqueues the job with the specified delay
# * <tt>:wait_until</tt> - Enqueues the job at the time specified
# * <tt>:queue</tt> - Enqueues the job on the specified queue
#
# ==== Examples
#
# my_job_instance.enqueue
# my_job_instance.enqueue in: 5.minutes
# my_job_instance.enqueue wait: 5.minutes
# my_job_instance.enqueue queue: :important
# my_job_instance.enqueue at: Date.tomorrow.midnight
# my_job_instance.enqueue wait_until: Date.tomorrow.midnight
def enqueue(options={})
self.scheduled_at = options[:in].seconds.from_now.to_f if options[:in]
self.scheduled_at = options[:at].to_f if options[:at]
self.scheduled_at = options[:wait].seconds.from_now.to_f if options[:wait]
self.scheduled_at = options[:wait_until].to_f if options[:wait_until]
self.queue_name = self.class.queue_name_from_part(options[:queue]) if options[:queue]
run_callbacks :enqueue do
if self.scheduled_at