Skip to content

Commit

Permalink
Rename remaining :in / :at to :wait / :wait_until
Browse files Browse the repository at this point in the history
  • Loading branch information
cristianbica committed Sep 4, 2014
1 parent 1e237b4 commit 15ddf60
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 25 deletions.
21 changes: 9 additions & 12 deletions actionmailer/lib/action_mailer/message_delivery.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ def message
# 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
Expand All @@ -54,13 +54,13 @@ def deliver_later!(options={})
# 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
Expand Down Expand Up @@ -98,10 +98,7 @@ def deliver #:nodoc:

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
8 changes: 5 additions & 3 deletions actionmailer/test/message_delivery_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,17 @@ def test_should_enqueue_and_run_correctly_in_activejob
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

Expand Down
2 changes: 0 additions & 2 deletions activejob/lib/active_job/configured_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 8 additions & 8 deletions activejob/lib/active_job/enqueuing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ def job_or_instantiate(*args)
# 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
Expand All @@ -48,19 +48,19 @@ def retry_job(options={})
# 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
Expand Down

0 comments on commit 15ddf60

Please sign in to comment.