Replies: 2 comments 2 replies
-
Some of those (timezone, i18n locale) are already included in the Active Job. For everything else, I think you should do this as an ActiveJob extension for serializing data into the job record. I'm happy to work through what is needed because nearly everything is possible by extending Active Job without adding hooks to GoodJob... but I want to know if it isn't and address that. I would design something generic that could be used like this: module FoobarExtension
extend ActiveSupport::Concern
included do
prepend Prepends
attr_accessor :foobar
end
module Prepends
# `options` are passed into `MyJob.set(options)...`
def enqueue(options = {})
if options.key?(:foobar)
self.foobar = options[:foobar]
else
self.foobar = Thread.current[:foobar] # some implicit / thread-local state
end
super
end
def serialize
super.tap do |job_data|
job_data["foobar"] = foobar unless foobar.nil?
end
end
def deserialize(job_data)
super
self.foobar = job_data["foobar"]
end
end
end
class ApplicationJob
include FoobarExtension
end |
Beta Was this translation helpful? Give feedback.
-
@bensheldon Has anyone already crafted AJ extension to handle CurrentAttributes? |
Beta Was this translation helpful? Give feedback.
-
We're currently using Sidekiq as job processor but would like to move to GoodJob.
We do use the Sidekiq middleware for various things like preserving the
I18n.locale
, setting theCurrentAttributes
(https://github.com/sidekiq/sidekiq/blob/main/lib/sidekiq/middleware/current_attributes.rb) and keep track of distributed tracing IDs.Is there a similar concept in GoodJob to hook into the enqueueing / dequeuing with the ability to store custom metadata beside the job's arguments? Because I want to avoid having to pass the metadata (such as request ID, tracing ID) as job arguments.
Beta Was this translation helpful? Give feedback.
All reactions