From f8d5975e72653926684c1e797fa25dd96cc624ee Mon Sep 17 00:00:00 2001 From: Marc Greenstock Date: Thu, 23 Nov 2017 20:29:36 +0100 Subject: [PATCH] added delay to long error --- .../active_elastic_job_adapter.rb | 19 +++++++++++++------ .../active_elastic_job_adapter_spec.rb | 5 +++-- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/lib/active_job/queue_adapters/active_elastic_job_adapter.rb b/lib/active_job/queue_adapters/active_elastic_job_adapter.rb index 71d8921..ecd9d75 100644 --- a/lib/active_job/queue_adapters/active_elastic_job_adapter.rb +++ b/lib/active_job/queue_adapters/active_elastic_job_adapter.rb @@ -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 @@ -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 diff --git a/spec/active_job/queue_adapters/active_elastic_job_adapter_spec.rb b/spec/active_job/queue_adapters/active_elastic_job_adapter_spec.rb index 30b2e3a..dd41170 100644 --- a/spec/active_job/queue_adapters/active_elastic_job_adapter_spec.rb +++ b/spec/active_job/queue_adapters/active_elastic_job_adapter_spec.rb @@ -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