diff --git a/lib/quiq/job.rb b/lib/quiq/job.rb index b4de0bc..c2d6c18 100644 --- a/lib/quiq/job.rb +++ b/lib/quiq/job.rb @@ -15,12 +15,12 @@ def run # First parse the raw message from redis payload = JSON.parse(@raw) - # Then load the definition of the job + its arguments + # Then load the definition of the job + deserialize it to a job object klass = Object.const_get(payload['job_class']) - args = payload['arguments'] + job = klass.deserialize(payload) # Then run the task - klass.new.perform(*args) + job.perform_now rescue JSON::ParserError => e Quiq.logger.warn("Invalid format: #{e}") send_to_dlq(@raw, e) diff --git a/testapp/app/jobs/retry_job.rb b/testapp/app/jobs/retry_job.rb new file mode 100644 index 0000000..1379a9e --- /dev/null +++ b/testapp/app/jobs/retry_job.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class RetryJob < ApplicationJob + class CustomError < StandardError; end + + retry_on(CustomError, wait: 5, attempts: 3, queue: :retry) do + raise + end + + def perform(data, wait) + puts "[Worker ##{$$}] Receiving new job: #{data}" + Quiq.current_task.sleep wait + puts "[Worker ##{$$}] Time to wake up after #{wait} seconds" + raise CustomError, 'Caught CustomError' + end +end