Skip to content

don't push new job for each item if ttr is null #17058

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

Merged
merged 3 commits into from
Apr 10, 2025

Conversation

i-just
Copy link
Contributor

@i-just i-just commented Apr 10, 2025

Description

The check to ensure we didn’t hit the TTL was kicking in for every batched job that had the ttr set to null, causing a new job to be added to the queue for each item that needed to be processed.

Example:

  • have an install with 2 sites and a section enabled for only one site
  • go and enable that section for the second site
  • the ResaveElements job gets triggered with ttr set to null (default), and each item it’s supposed to resave is pushed to the queue as a new job

Related issues

n/a

@i-just i-just requested a review from timkelty April 10, 2025 10:34
@timkelty
Copy link
Contributor

@i-just this makes sense, but curious where it was happening? In core or a plugin?

  • ::: warning
  • Batched jobs should always be pushed to the queue using [[QueueHelper::push()]],
  • so the priority and ttr settings can be maintained for additional spawned jobs.
  • :::

Seems like anywhere pushing a batched job should but using the helper, and thus, shouldn't have a null ttr.

@i-just
Copy link
Contributor Author

i-just commented Apr 10, 2025

The easiest way to reproduce is to use the steps from my example - that’s as core as it can be, right? In the example I described, the ResaveElements job is triggered from here

It also happens with Feed Me import (that’s how I discovered it).

@i-just
Copy link
Contributor Author

i-just commented Apr 10, 2025

So they will be maintained if they’re set in the first place, but if they’re not set then they default to null.

@timkelty
Copy link
Contributor

So they will be maintained if they’re set in the first place, but if they’re not set then they default to null.

I think we need to do something like this in init/constructor:

$this->ttr = $this->ttr ?? Craft::$app->getQueue()->ttr;

@i-just
Copy link
Contributor Author

i-just commented Apr 10, 2025

@timkelty, as per our chat, I pushed a change we agreed on to ensure the ttr is set (even if to a default value)

@i-just i-just requested a review from brandonkelly April 10, 2025 12:34
[ci skip]
@brandonkelly brandonkelly merged commit 6490b02 into 4.15 Apr 10, 2025
@brandonkelly brandonkelly deleted the bugfix/batched-jobs-and-ttr branch April 10, 2025 19:09
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.

3 participants