Skip to content

Mainwilliam/pro 670 make the cleanup routine for orphaned issues run twice a day #1580

Open
pattonwebz wants to merge 4 commits intodevelopfrom
mainwilliam/pro-670-make-the-cleanup-routine-for-orphaned-issues-run-twice-a-day--
Open

Mainwilliam/pro 670 make the cleanup routine for orphaned issues run twice a day #1580
pattonwebz wants to merge 4 commits intodevelopfrom
mainwilliam/pro-670-make-the-cleanup-routine-for-orphaned-issues-run-twice-a-day--

Conversation

@pattonwebz
Copy link
Copy Markdown
Member

@pattonwebz pattonwebz commented Mar 19, 2026

This pull request updates the scheduling logic for the orphaned issues cleanup event to allow for more flexible and maintainable recurrence intervals. The main focus is on introducing a class constant for the recurrence setting and ensuring the event is rescheduled if the recurrence changes.

Scheduling improvements:

  • Introduced a RECURRENCE class constant in class-orphaned-issues-cleanup.php to define the cleanup event's recurrence interval, making it easier to update and maintain.
  • Updated the schedule_event method to check if the event is scheduled with the correct recurrence, and if not, unschedule and reschedule it with the new interval. This ensures the event always uses the latest recurrence configuration.

Checklist

  • PR is linked to the main issue in the repo
  • Tests are added that cover changes

Summary by CodeRabbit

  • Chores
    • Updated scheduled cleanup frequency from daily to twice daily.
    • Enhanced scheduling to detect existing scheduled events and only reschedule when recurrence changes.
    • Improved unscheduling to reliably clear existing scheduled hooks.
    • Minor housekeeping cleanup (non-functional whitespace removal).

Copilot AI review requested due to automatic review settings March 19, 2026 13:27
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the orphaned issues cleanup routine by making its scheduling more robust and maintainable. It introduces a dedicated class constant for defining the recurrence interval and ensures that the cleanup event is always scheduled with the latest configuration, specifically setting it to run twice daily. This change improves the reliability and flexibility of the background task management.

Highlights

  • Introduced RECURRENCE Constant: A new class constant RECURRENCE was added to class-orphaned-issues-cleanup.php to explicitly define the cleanup event's recurrence interval as 'twicedaily', centralizing the scheduling configuration.
  • Dynamic Event Rescheduling Logic: The schedule_event method was updated to dynamically manage the cleanup event's recurrence. It now checks if the event is already scheduled and, if its recurrence differs from the RECURRENCE constant, it unschedules the old event and reschedules it with the correct, updated recurrence.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 19, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 5f5d5652-6745-461f-ac4d-3873a06bc4da

📥 Commits

Reviewing files that changed from the base of the PR and between d56c1bd and 8760b72.

📒 Files selected for processing (1)
  • admin/class-orphaned-issues-cleanup.php
🚧 Files skipped from review as they are similar to previous changes (1)
  • admin/class-orphaned-issues-cleanup.php

📝 Walkthrough

Walkthrough

The orphaned issues cleanup class adds a RECURRENCE constant ('twicedaily'), updates scheduling to inspect and conditionally reschedule cron events via wp_get_scheduled_event() and wp_clear_scheduled_hook(), and removes a whitespace-only line in get_orphaned_post_ids().

Changes

Cohort / File(s) Summary
Cron scheduling & unscheduling
admin/class-orphaned-issues-cleanup.php
Added const RECURRENCE = 'twicedaily'. schedule_event() now checks existing cron entries with wp_get_scheduled_event() and reschedules if the recurrence differs; previously hardcoded 'daily'. unschedule_event() now clears hooks via wp_clear_scheduled_hook() instead of unscheduling a specific timestamp. Removed a whitespace-only line.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I nudged a constant into the code,
Twice-daily beats the single-mode,
I check the schedule, clear the mess,
Reschedule tidy, no distress,
Hopping on — the cron's bestowed.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly describes the main change: updating the cleanup routine to run twice a day instead of once daily, which aligns with the PR objectives.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch mainwilliam/pro-670-make-the-cleanup-routine-for-orphaned-issues-run-twice-a-day--
📝 Coding Plan
  • Generate coding plan for human review comments

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 PHPStan (2.1.40)

Composer install failed: this project depends on private packages that require authentication (e.g. GitLab/GitHub, Laravel Nova, etc.).
CodeRabbit tooling environment cannot access private registries.
If your project requires private packages, disable the PHPStan tool in your coderabbit settings.

Instead, run PHPStan in a CI/CD pipeline where you can use custom packages — our pipeline remediation tool can use the PHPStan output from your CI/CD pipeline.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the scheduling logic for the orphaned issues cleanup event to be more flexible. The introduction of a RECURRENCE constant and logic to reschedule the event if the recurrence changes are good improvements. I've suggested a small refactoring to the schedule_event method to make the logic more concise and robust by using wp_clear_scheduled_hook and simplifying the conditional checks.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the orphaned-issues cleanup cron scheduling to run twice per day and makes the recurrence easier to maintain by centralizing it in a class constant, while also ensuring the cron event is rescheduled if the configured recurrence changes.

Changes:

  • Added a RECURRENCE class constant (set to twicedaily) for the cleanup cron schedule.
  • Updated schedule_event() to detect an existing scheduled event and reschedule it if the recurrence differs.

Comment on lines +79 to +81
if ( self::RECURRENCE !== $event->schedule ) {
wp_unschedule_event( $event->timestamp, self::EVENT );
wp_schedule_event( time(), self::RECURRENCE, self::EVENT );
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

There should not be situations where there are several hooked in. We only ever scheduled one. But if there are several that isn't a huge problem because it just means it will clear orphans faster.

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