-
-
Notifications
You must be signed in to change notification settings - Fork 280
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow SQS SendMessage options (e.g., message_attributes, message_deduplication_id, and message_group_id) to be specified when using ActiveJob to enqueue messages #646
Comments
One natural API might be to encode Shoryuken options in the job arguments: class AddJob < ActiveJob::Base
def perform(a, b)
puts a + b
end
end
AddJob.perform_later 123, 'abc', shoryuken_options: {
message_group_id: 'abc123',
message_deduplication_id: 'dedupe',
message_attributes: {
'key' => {
string_value: 'myvalue',
data_type: 'String'
}
}
} But it's not clear how to get this to work. If we make it so that the |
The best option I've come across is to use MyJob.set(message_group_id: 'abc123',
message_deduplication_id: 'dedupe',
message_attributes: {
'key' => {
string_value: 'myvalue',
data_type: 'String'
}
})
.perform_later 123, 'abc' |
@timbreitkreutz I'm just curious: since you mentioned that your application specifies additional class MyJob < ActiveJob::Base
end
job = MyJob.new 'arg1', 'arg2'
MyJob.queue_adapter.enqueue job,
message_attributes: {
'key' => {
string_value: 'myvalue',
data_type: 'String'
}
} |
Using While testing it, I noticed there's one thing I think I want to change before I close the issue and ship a new version: the |
Sorry @cjlarose didn't see your question earlier. Essentially in a middleware we are doing something like: class ShoryukenClientMetrics
def call(options)
options[:message_attributes].merge!(message_attributes(options))
yield
end
def message_attributes(options)
{
"app_enqueued_at" => {
data_type: "Number",
string_value: (Time.now.to_f + options[:delay_seconds].to_f).to_s
}
}
end |
@timbreitkreutz Are you using that class ShoryukenClientMetrics
def call(options)
options[:message_attributes].merge!(message_attributes(options))
yield
end
def message_attributes(options)
{
"app_enqueued_at" => {
data_type: "Number",
string_value: (Time.now.to_f + options[:delay_seconds].to_f).to_s
}
}
end
end
Shoryuken.configure_client do |config|
config.client_middleware do |chain|
chain.add ShoryukenClientMetrics
end
end
AddJob.perform_later(123, 321) |
Support for setting SQS SendMessage parameters via |
When enqueuing a message with
ActiveJob
'sperform_later
method, it is not currently possible to specify SQS-specific options like themessage_group_id
,message_deduplication_id
, or additionalmessage_attributes
. There doesn't appear to be much thatActiveJob
offers in terms of being able to specify queue-adapter-specific options, but that kinda makes sense: it's meant to provide the common-denominator interface for all queue adapters.It's desirable to use
ActiveJob
for some folks so they can write workers in a way that is queue-adapter-agnostic. In testing environments especially, it's nice to be able to swap out the adapter for the:async
or:inline
adapters.It desirable, too, to be able to specify SQS-specific options when the server-side (enqueue-side) code is actually using the
:shoryuken
adapter. It's possible to useShoryukenAdapter
's API directly in order to specifymessage_group_id
,message_deduplication_id
, andmessage_system_attributes
, andmessage_attributes
(since #635) like this:However, this isn't really documented and actually shouldn't be encouraged because code like this won't work when you swap out
ActiveJob
backends. Ideally, we'd have a solution where users could specify SQS-specific options in a way that, when executed against different backends, those options were ignored.Related discussion:
📌 #648
The text was updated successfully, but these errors were encountered: