Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/quiq/job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

neat!

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: is it a rails/activejob primitive? If so it means that the system won't be usable outside of the rails ecosystem.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we should use if defined? ActiveJob here

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the retry mechanism is a rails/activejob primitive, but the serialize(which is used in Quiq::Client#push) and deserialize are probably not.

if defined? ActiveJob could be done during the server booting, wdyt?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes it could probably do the job!


# 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)
Expand Down
16 changes: 16 additions & 0 deletions testapp/app/jobs/retry_job.rb
Original file line number Diff line number Diff line change
@@ -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