Repository navigation
Change the suggestion about adapters and enqueue_after_transaction_commit - #52659
Conversation
…ommit` Solid Queue will set this to `:always` by default so the comment could be confusing for people using it with the same DB as the app. See rails/solid_queue#212 (comment)
|
Actually, what adapters do set something else by default? I don't love the :default option being this mystery box that's dependent on the adapter. That just seems confusing. I think this setting should just either be true or false. Even the |
|
@dhh GoodJob sets it to Something I found a bit confusing is that the adapter is expected to return |
|
In fact I made that mistake myself in this PR description! I said:
But I meant:
😅 |
|
That's all just way too confusing. I think we need to stop delegating this to the adapter. And instead we simply go with enqueue_after_transaction_commit = true|false. That's clear. Feel like this is the kind of change that it's fine to be strict about. So we can simply raise an exception if it's set to one of the old symbols and explain what folks need to do instead. cc @rafaelfranca |
|
We delegate to the adapter because I think our users should not have to decide this. If they swap from SolidQueue to Sidekiq, they should not have to know they also need to change But, if adapters are themselves making people chose which value they should set for this option, like it seems GoodJob is, then I agree we should just use the boolean. |
No, I don't think GoodJob is doing that, GoodJob is choosing a value because it needs to, adapters need to return So, I don't think adapters are making people choose. It's rather Active Job is making adapters choose, and then the user needs to know what the adapter chose. |
So, with the current behaviour of delegating to the adapter, what happens is that the behaviour might change from under the user without them knowing when changing adapters. To ensure the behaviour doesn't change under them, users would need to opt for I'd say it's Active Job's behaviour what forces the user to know and choose 🤔 I might be missing something here, about why it was implemented this way. I'll review the original PR that introduced this setting. |
|
I've re-read all comments in #51426, and it seems the idea with the adapter delegation and the different values I also noticed |
I mean this line here https://github.com/luizkowalski/good_job/blob/8a2e3d7f6280956297d6dc401ae0dcc715e8500a/lib/good_job/configuration.rb#L397. It seems GoodJob allow users to change that value. Rails is defaulting to We can change this option to be a boolean, but then the job adapter will have to do like That is why I think this should be up to the adapters. They know what they support. |
Ohhhh! I totally missed that! So sorry. Now what you say makes sense. I think, for the user, it doesn't make sense to change this in both places, the adapter and active job configuration 🤔 I suppose most won't change it there.
That sounds good to me, I still find the whole thing a bit confusing, but I imagine that if the defaults make sense, most people won't need to worry about this at all? |
That is my hope as well. Not sure how that will pan out, but given 7.2 leaves this to the adapters and people don't need to chose, if we see reports that people need to explicitly set this value we can totally simplify and take ownership of setting this config in the framework. |
I don't think this is a good path, to be honest. First of all, the setting is altering a setting on our end with when the job is actually enqueued, no? Like we handle the delay until the transaction commit. But more importantly, it's of critical importance that people actually understand just how sharp the knife of queuing within the transaction is. And that it's a recipe of bad surprises if hopping from one adapter to another changes that underneath you. I think we must make the user responsible for this choice. I ALSO think that this is very rarely going to be used. Which actually brings me to a more natural conclusion: We shouldn't offer this setting at all. If it's that sharp, that rarely used, and we don't have anyone on core who'd actually use it themselves, it's not a good knife. And I say that knowing that I advocated for the inclusion of this feature for quite a while! And I remember that @byroot trying to convince me it wasn't a good idea at the last Rails World core meeting, and I thought that it was, and I realize that I was wrong 😂 In other words, I think the right path forward is simply to drop this feature entirely. Don't offer a path to enqueue within the transaction. Accept that we give up on some potential benefit, but that the situation it's available in is just too narrow or too time limited. |
I think it might get used more than this, but on very specific cases, and not necessarily because of the advantages of having jobs in the same DB as the app. We use this ourselves for cases where not enqueuing the job would mean ending up with serious inconsistencies. If we always defer to after all transactions are committed and can't even check if the job was successfully enqueued, we're in trouble. This is the case even if the adapter uses Redis. I think we shouldn't lose this. What we should avoid is the inadvertent dependency on jobs being enqueued within a transaction, but that'd be covered by Rails's default and the adapter's default. |
|
Just to make sure I understood, @dhh you are advocating that we always keep rails with the behavior of I have no problem with that, is it is what we advocated, but I thought we wanted to allow ACID adapters to enqueue the job inside the transaction. If you don't believe SQ will do that, I don't see why we should let adapters chose it. We can allow |
I'd be totally fine with that as long as the user can still opt out of this behaviour for specific jobs, as it is now 😅 In Solid Queue we're planning to set |
|
Yeah. I'd keep the ability of changing this per job. I think what we are discussing here is if we should delegate to the adapter and the |
|
Yeah, I'm saying we shouldn't expose this as a top-level setting that we encourage neither people nor adapters to mess with. In terms of timing, yes, totally fine that a job can overwrite this, just as long as we document the issues with ACID. You're not going to get that job rolled back if the txn fails when the SQ db is separate from the app DB. |
|
Opened an issue so we don't forget to do it #52675 |
|
For perspective, when I launched GoodJob I was surprised by the interest and awareness by developers for transactional integrity when enqueuing jobs, and that was a major adoption-reason for GoodJob. This was not on my radar initially and I have since emphasized that more. When developers are considering alternate backends, I think they are intensely studying the spec-sheets, and transactional integrity as a checkbox is pretty high on that list. The reason I exposed the Developmentally, I think someone's new application defaults would ideally include transactional integrity, and then as their application grows (or they add additional customization / non-omakase things) only then do they have to consider transactional integrity as something they can lose. It's not the end of the world if this configuration is deprecated, but I imagine part of GoodJob's setup guide would be to tell people to enable transactional-integrity for all jobs (or whatever mechanism that was) with some notes/caveats (not cause I'm driving that necessarily, but I know that someone else will suggest it). Devs will be coming to GoodJob's docs for setup and usage guidance not Rails' docs. I feel like that's the adapter's responsibility to provide a good experience with the sharp knives. |
|
Great points, @bensheldon 🙏 Thanks a lot for writing that up. I agree with pretty much everything. I used to feel very strongly about transactional integrity as a feature (advocating for it, I mean) but I learnt this was not what Rails Core wanted, more the opposite. Since that's not my call, I just want to make things as simple and clear as possible and don't mind jumping extra hoops for the cases where I want a job enqueued within a transaction, for whatever reason 😅 The discussion is all around transaction integrity but there are other reasons why you don't want to defer enqueuing to after all transactions have committed. As I said, one big disadvantage of the current implementation, transactional integrity aside, is that you have no way to know if a job was enqueued or not because This is also quite interesting, I didn't know this:
I thought this was a minor factor; it's good to know it's not. Thanks for explaining why you exposed
Yes, that makes sense, too, and since it should be possible to set it application-wide, it shouldn't be too much of a problem 🤔 |
|
Just as an implementation detail, removing the global config and keeping the per-job config doesn't remove the global config since one could do: class ApplicationJob < ActiveJob::Job
self.enqueue_after_transaction_commit = false
endThe work will mostly to simplify the config to be |
…ging it See the discussion in rails/rails#52659. Adapters should set their own behaviour without making users choose. If users want to choose, they can just use Active Job's configuration. Besides, we're changing the value of this to `true` to make it harder for people to run into trouble in the future when switching adapters.
…ging it See the discussion in rails/rails#52659. Adapters should set their own behaviour without making users choose. If users want to choose, they can just use Active Job's configuration. Besides, we're changing the value of this to `true` to make it harder for people to run into trouble in the future when switching adapters.
…ging it See the discussion in rails/rails#52659. Adapters should set their own behaviour without making users choose. If users want to choose, they can just use Active Job's configuration. Besides, we're changing the value of this to `true` to make it harder for people to run into trouble in the future when switching adapters.
…ging it See the discussion in rails/rails#52659. Adapters should set their own behaviour without making users choose. If users want to choose, they can just use Active Job's configuration. Besides, we're changing the value of this to `true` to make it harder for people to run into trouble in the future when switching adapters.
…ging it See the discussion in rails/rails#52659. Adapters should set their own behaviour without making users choose. If users want to choose, they can just use Active Job's configuration. Besides, we're changing the value of this to `true` to make it harder for people to run into trouble in the future when switching adapters.
…ging it See the discussion in rails/rails#52659. Adapters should set their own behaviour without making users choose. If users want to choose, they can just use Active Job's configuration. Besides, we're changing the value of this to `true` to make it harder for people to run into trouble in the future when switching adapters.
…ging it See the discussion in rails/rails#52659. Adapters should set their own behaviour without making users choose. If users want to choose, they can just use Active Job's configuration. Besides, we're changing the value of this to `true` to make it harder for people to run into trouble in the future when switching adapters.
…ging it See the discussion in rails/rails#52659. Adapters should set their own behaviour without making users choose. If users want to choose, they can just use Active Job's configuration. Besides, we're changing the value of this to `true` to make it harder for people to run into trouble in the future when switching adapters.
After discussing with @dhh about this, Solid Queue will set this to
:alwaysby default so the comment could be confusing for people using it with the same DB as the app.See rails/solid_queue#212 (comment)