Skip to content

Respect doing_cron transient in wp cron event run --due-now - #130

Merged
swissspidy merged 10 commits into
mainfrom
copilot/add-no-doubles-flag-for-cron
Mar 16, 2026
Merged

Respect doing_cron transient in wp cron event run --due-now#130
swissspidy merged 10 commits into
mainfrom
copilot/add-no-doubles-flag-for-cron

Conversation

Copilot AI commented Mar 15, 2026

Copy link
Copy Markdown
Contributor
  • Explore codebase and understand the issue
  • Modify run() in src/Cron_Event_Command.php to check/set/delete the doing_cron transient when --due-now is used
  • Add Behat test in features/cron-event.feature covering the transient lock check
  • Use standard doing_cron transient with plain numeric microtime value (same format as WordPress core)
  • Fix CI failure: add DISABLE_WP_CRON true at the start of cron.feature:309 to prevent spawn_cron() from setting doing_cron between test steps
  • Pass $lock_timeout as TTL to set_transient() so lock self-expires on unexpected termination
  • Store lock value; only delete transient if it still matches our value (prevents wiping another process's lock)
  • All static checks pass (lint, phpcs, phpstan)
Original prompt

This section details on the original issue you should resolve

<issue_title>wp cron event run --due-now doesn't respect doing_cron transient</issue_title>
<issue_description>I use wp cron event run --due-now as my production cron. Every 5 minutes. But it's a heavy cron. Sometimes it takes more then 5 minutes. When that happens some events get executed twice. Mostly sending emails.

I would suggest a --no-doubles flag or something like that to prevent the cron from doing hooks twice.

When the flag is set, wp-cli should check for the doing_cron transient like core does. And set it if it's starting. Like core does.

Relevant core code

Why is it doing things twice

At the start of a cron all tasks are gathered with _get_cron_array, events get deleted once the start. And the remaing cron array is still executed. And still in the DB list So after 5 minutes the new cron get also does a _get_cron_array and will get all events that the first cron also is still handling (and deleting as it goes).</issue_description>

<agent_instructions>See previous attempts at https://gist.github.com/danielbachhuber/e76c5c5e1479c385863cc86f5f21eb87 and https://gist.github.com/danielbachhuber/800870993ce975f7e775219180cc37fa</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@danielbachhuber 👍 Seems reasonable. @schlessera I think this should even be the default behavior. I wouldn't consider this a breaking change, I'd classify this as a bug: We're diverting from expected Core behavior.

💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.

@codecov

codecov Bot commented Mar 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.71429% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/Cron_Event_Command.php 85.71% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot AI changed the title [WIP] Add no-doubles flag for wp cron event run Respect doing_cron transient in wp cron event run --due-now Mar 15, 2026
Copilot AI requested a review from swissspidy March 15, 2026 08:03
Comment thread features/cron-event.feature Outdated
Comment thread features/cron-event.feature Outdated
@swissspidy

This comment was marked as resolved.

…nsient

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>

This comment was marked as resolved.

Copilot AI requested a review from swissspidy March 16, 2026 10:17
@swissspidy

This comment was marked as resolved.

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>

This comment was marked as resolved.

@swissspidy

This comment was marked as resolved.

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>

This comment was marked as resolved.

@swissspidy

This comment was marked as resolved.

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>

This comment was marked as resolved.

@swissspidy
swissspidy marked this pull request as ready for review March 16, 2026 13:36
@swissspidy
swissspidy requested a review from a team as a code owner March 16, 2026 13:36
Copilot AI review requested due to automatic review settings March 16, 2026 13:36

This comment was marked as resolved.

@swissspidy

This comment was marked as resolved.

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>

This comment was marked as resolved.

@swissspidy swissspidy added this to the 2.3.5 milestone Mar 16, 2026
@swissspidy
swissspidy merged commit 969c27c into main Mar 16, 2026
111 of 113 checks passed
@swissspidy
swissspidy deleted the copilot/add-no-doubles-flag-for-cron branch March 16, 2026 14:35
@swissspidy swissspidy mentioned this pull request Mar 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

command:cron-event-run Related to 'cron event run' command scope:distribution Related to distribution state:unconfirmed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

wp cron event run --due-now doesn't respect doing_cron transient

3 participants