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

Implement enqueue_after_transaction_commit? #1311

Merged
merged 5 commits into from
Apr 4, 2024

Conversation

luizkowalski
Copy link
Contributor

@luizkowalski luizkowalski commented Apr 3, 2024

Closes #1310

It defines whether the job should be enqueued implicitly after committing an ActiveRecord transaction. More details here

@luizkowalski
Copy link
Contributor Author

I'm just not sure how to test it here since this is just an option passed to AJ, and it is being tested there already. Do you have any idea?

It defines whether the job should be enqueued implicitly after committing an ActiveRecord transaction
@luizkowalski luizkowalski force-pushed the enqueue-after-commit branch from 51fa814 to 76155bf Compare April 3, 2024 20:04
Copy link
Owner

@bensheldon bensheldon left a comment

Choose a reason for hiding this comment

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

Let's set the default to false because we do have the option of transactional integrity. Otherwise this looks good 👍

@bensheldon
Copy link
Owner

And don't worry about tests. We'll trust Active Job.

@luizkowalski
Copy link
Contributor Author

it is worth mentioning that I tested locally with my app, and it worked

@luizkowalski
Copy link
Contributor Author

I am scratching my head trying to fix the failure: using instance_double to double ActiveJob::QueueAdapters::InlineAdapter doesn't work on Rails edge but works for GA versions. Adding :enqueue_after_transaction_commit? false then works on edge but fails on GA since the commit was not backported (nor do I think it will?). I could change to double instead. It's not ideal, but it gives us the flexibility to handle different versions of InlineAdapter.

Have you seen such a problem? what's your take on this one? There's only one other place where double is used in tests, so I know it is not the preferred way to go

@bensheldon
Copy link
Owner

hmm. It's not pretty but what about something like this?

optional_adapter_kwargs = ActiveJob::QueueAdapters::InlineAdapter.method_defined?(:enqueue_after_transaction_commit?) ? { enqueue_after_transaction_commit?: false } : {}
adapter = instance_double(ActiveJob::QueueAdapters::InlineAdapter, enqueue: nil, enqueue_at: nil, **optional_adapter_kwargs)

@luizkowalski
Copy link
Contributor Author

that should do it

@bensheldon
Copy link
Owner

Thanks for all the help on this! I decided to lift it up to a global configuration because the reason why someone would use this---they're using a separate database for jobs---would be a global decision rather than per-Adapter. I'll get this merged and cut a release and unblock you 🚀

@luizkowalski
Copy link
Contributor Author

that’s actually a great idea! thanks for the quick follow up, ben! ❤️

@bensheldon bensheldon merged commit facec21 into bensheldon:main Apr 4, 2024
20 checks passed
@bensheldon
Copy link
Owner

Released! https://github.com/bensheldon/good_job/releases/tag/v3.27.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

Adapter to implement enqueue_after_transaction_commit
2 participants