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

Handle proper values for ActiveJob.enqueue_after_transaction_commit for Rails 7.2 support #43

Merged
merged 1 commit into from
Aug 13, 2024

Conversation

warmerzega
Copy link
Contributor

Hi Betterment friends!

As addressed in @smudge's PR #40, Rails 7.2 introduces the concept of enqueue_after_transaction_commit, which should not be used in conjunction with Delayed. The implementation, and the associated tests, make the assumption that the values used by ActiveJob are true and false. The implementation in ActiveJob::EnqueueAfterTransactionCommit (https://github.com/rails/rails/blob/ac1d7681d05906b2b050eced76c6a2165f420821/activejob/lib/active_job/enqueue_after_transaction_commit.rb#L7-L14) uses the values of :always and :never. The issues arises when hitting the conditional check (https://github.com/Betterment/delayed/compare/main...warmerzega:delayed:main?expand=1#diff-325ce2458ac2c3e05143813a4899c9f996ae51f54cdb8fa5f79f50efab872f9aR20) where !!:never == true and causes the condition to be true (and raising the exception) when job.class.enqueue_after_transaction_commit == :never.

@@ -17,7 +17,7 @@ def enqueue_at(job, timestamp)
private

def _enqueue(job, opts = {})
if job.class.respond_to?(:enqueue_after_transaction_commit) && job.class.enqueue_after_transaction_commit
if job.class.respond_to?(:enqueue_after_transaction_commit) && job.class.enqueue_after_transaction_commit == :always
Copy link
Contributor Author

@warmerzega warmerzega Aug 13, 2024

Choose a reason for hiding this comment

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

This isn't the perfect solution to this problem. The implementation in ActiveJob::EnqueueAfterTransactionCommit does allow for unset (or non :always/:never) values which then gets delegated to job_adapter.enqueue_after_transaction_commit?. Given the job adapter will always be delayed, if a non :always value is passed in, it will always be false

Copy link
Member

Choose a reason for hiding this comment

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

Yup, that was my read as well.

But, gosh, that Rails API seems like it's going to cause such confusion. I.e. you could set def self.enqueue_after_transaction_commit; true; end and then it goes down the false codepath because nothing about the API itself checks for completeness on :always/:never/:default. 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, feels like there is a missing validation on the value you are passing in.

Copy link
Member

@smudge smudge Oct 25, 2024

Choose a reason for hiding this comment

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

gem 'actionmailer', '~> 7.2.0'
gem 'activejob', '~> 7.2.0'
gem 'activerecord', '~> 7.2.0'
end
Copy link
Contributor Author

Choose a reason for hiding this comment

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

TODO: Finish Appraisal set up for Rails 7.2

Copy link
Member

Choose a reason for hiding this comment

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

Do you intend to do that in this PR?

(While you're at it, mind bumping the delayed gem's version?)

Copy link
Contributor Author

@warmerzega warmerzega Aug 13, 2024

Choose a reason for hiding this comment

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

Yep. Was struggling to get the incantation working to build/install mysql. Should be good now

Copy link
Member

Choose a reason for hiding this comment

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

I think the version bump requires an update to all of the lockfiles.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Bumped

@warmerzega warmerzega force-pushed the main branch 3 times, most recently from b93fb8f to 528cb72 Compare August 13, 2024 21:01
- ruby: '3.0'
gemfile: gemfiles/rails_5_2.gemfile
- ruby: '2.7'
gemfile: gemfiles/rails_7_2.gemfile
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Rails 7.2 has a minimum version of Ruby 3.1. Not sure if I should add an exclusion for Ruby 2.6. Got a sense from this PR that we may be removing Ruby 2.6 support? #42

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, this is fine for now! Fully dropping Ruby 2.6 doesn't need to be part of this PR.

Copy link
Member

@smudge smudge left a comment

Choose a reason for hiding this comment

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

domain LGTM && platform LGTM!

@smudge smudge merged commit 37dff23 into Betterment:main Aug 13, 2024
20 checks passed
@smudge
Copy link
Member

smudge commented Aug 13, 2024

@warmerzega released!

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.

2 participants