Skip to content

Commit

Permalink
Merge pull request active-elastic-job#80 from marcgreenstock/add_dela…
Browse files Browse the repository at this point in the history
…y_too_long_error

RangeError is too general for the 15 minute max delay
  • Loading branch information
tawan authored Dec 10, 2017
2 parents f9ea8aa + f8d5975 commit a123340
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 a123340

Please sign in to comment.