Skip to content

Commit

Permalink
added delay to long error
Browse files Browse the repository at this point in the history
  • Loading branch information
marcgreenstock committed Nov 23, 2017
1 parent b193f11 commit f8d5975
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
19 changes: 13 additions & 6 deletions lib/active_job/queue_adapters/active_elastic_job_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,18 @@ def initialize(message_id, calculated, returned)
end
end

# Raised when the delay is longer than the MAX_DELAY_IN_MINUTES
class DelayTooLong < RangeError
def initialize()
super(<<-MSG)
Jobs cannot be scheduled more than #{MAX_DELAY_IN_MINUTES} minutes
into the future.
See http://docs.aws.amazon.com/AWSSimpleQueueService/latest/APIReference/API_SendMessage.html
for further details!
MSG
end
end

def enqueue(job) #:nodoc:
self.class.enqueue job
end
Expand Down Expand Up @@ -147,12 +159,7 @@ def queue_url(queue_name)
def calculate_delay(timestamp)
delay = (timestamp - Time.current.to_f).to_i + 1
if delay > MAX_DELAY_IN_MINUTES.minutes
msg = "Jobs cannot be scheduled more than " <<
"#{MAX_DELAY_IN_MINUTES} minutes into the future. " <<
"See http://docs.aws.amazon.com/AWSSimpleQueueService/latest/APIReference/API_SendMessage.html" <<
" for further details!"

raise RangeError, msg
raise DelayTooLong.new
end
delay = 0 if delay < 0
delay
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,9 @@ def initialize; end;
context "when scheduled timestamp exceeds 15 minutes" do
let(:delay) { 16.minutes }

it "raises a RangeError" do
expect { adapter.enqueue_at(job, timestamp) }.to raise_error(RangeError)
it "raises a DelayTooLong" do
expect { adapter.enqueue_at(job, timestamp) }
.to raise_error(ActiveJob::QueueAdapters::ActiveElasticJobAdapter::DelayTooLong)
end
end
end
Expand Down

0 comments on commit f8d5975

Please sign in to comment.