Skip to content
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 access to computed SQS SendMessage parameters when using ActiveJob #651

Merged

Conversation

cjlarose
Copy link
Contributor

@cjlarose cjlarose commented Feb 6, 2021

When enqueuing a message with ActiveJob, the SQS SendMessage parameters undergo several important transformations:

  • The shoryuken_class :message_attribute is added
  • Client middleware is applied
  • :message_group_id and :message_deduplication_id are set for FIFO queues if those options were unspecified

Since we store SQS SendMessage parameters on the ActiveJob job instance itself, they're accessible to the caller:

job = AddJob.set(queue: 'shoryuken_test.fifo')
            .perform_later(123, 321)
job.sqs_send_message_parameters

This change modifies the sqs_send_message_parameters reference to be the same object that's sent into Shoryuken::Queue#send_message. That way, the caller has access to the complete set of computed SQS
SendMessage parameters, not just the ones that were specified by the caller (for example, when using .set).

This makes it possible, for instance, to log important information like the message_deduplication_id on the enqueuer side. It also gives important feedback to users so that they know exactly what parameters were sent to SQS.

Related: #646

This'll help ensure that the ActiveJob adapters continue to work with
all supporter versions of ActiveJob.

The `require` order is unfortunately very sensitive here: it's important
to force the `:autoload` of `ActiveJob::QueueAdapters` (for example, by
defining a subclass of `ActiveJob::Base`) before defining our own
`ActiveJob::QueueAdapters::Shoryuken{Adapter,ConcurrentSendAdapter}`.
Otherwise, we end up in a situation where class methods on
`ActiveJob::QueueAdapters` are not defined.
When enqueuing a message with ActiveJob, the SQS SendMessage parameters
undergo several important transformations:

* The `shoryuken_class` :message_attribute is added
* Client middleware is applied
* :message_group_id and :message_deduplication_id are set for FIFO
  queues if those options were unspecified

Since we store SQS SendMessage parameters on the ActiveJob job instance
itself, they're accessible to the caller:

```ruby
job = AddJob.set(queue: 'shoryuken_test.fifo')
            .perform_later(123, 321)
job.sqs_send_message_parameters
```

This change modifies the `sqs_send_message_parameters` reference to be
the same object that's sent into `Shoryuken::Queue#send_message`. That
way, the caller has access to the complete set of computed SQS
SendMessage parameters, not just the ones that were specified by the
caller (for example, when using `.set`).

This makes it possible, for instance, to log important information like
the `message_deduplication_id` on the enqueuer side. It also gives
important feedback to users so that they know exactly what parameters
were sent to SQS.
@cjlarose cjlarose merged commit f6b9c8f into ruby-shoryuken:master Feb 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant