feat: add jobs cleanup CLI command and auto-expiry#519
Merged
chubes4 merged 1 commit intoExtra-Chill:mainfrom Mar 3, 2026
Merged
feat: add jobs cleanup CLI command and auto-expiry#519chubes4 merged 1 commit intoExtra-Chill:mainfrom
chubes4 merged 1 commit intoExtra-Chill:mainfrom
Conversation
Add age-based job cleanup to prevent stale failed jobs from accumulating indefinitely in the wp_datamachine_jobs table. New WP-CLI command: wp datamachine jobs cleanup --older-than=30d --status=failed [--dry-run] [--yes] Supports duration formats: 30d (days), 4w (weeks), 72h (hours) Auto-cleanup: Daily Action Scheduler task deletes failed jobs older than 30 days. Max age is filterable via datamachine_failed_jobs_max_age_days. Database layer: JobsOperations::delete_old_jobs() and count_old_jobs() use LIKE prefix matching to handle compound statuses (e.g. 'failed - timeout'). Also wires up the deactivation hook to unschedule all maintenance actions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
wp datamachine jobs cleanup --older-than=30d --status=failedwith--dry-runand--yesflags. Supports30d,4w,72hduration formats.datamachine_failed_jobs_max_age_days).datamachine_deactivate_plugin()to unschedule alldatamachine-maintenancegroup actions on plugin deactivation.Problem
The
wp_datamachine_jobstable accumulates failed jobs indefinitely. At time of writing there were 400+ failed jobs dating back to February 3rd. No mechanism existed to expire old failures, making it harder to spot fresh problems.Changes
inc/Core/Database/Jobs/JobsOperations.phpdelete_old_jobs()andcount_old_jobs()— age + status-based deletion with LIKE prefix matching for compound statusesinc/Core/Database/Jobs/Jobs.phpinc/Cli/Commands/JobsCommand.phpcleanupsubcommand with duration parsing (30d/4w/72h), dry-run, and confirmationinc/Core/ActionScheduler/JobsCleanup.phpdatamachine_cleanup_failed_jobs)inc/bootstrap.phpdata-machine.phpTesting
Tested on production against live data:
Also verified: invalid duration error handling, different status targets (
completed,agent_skipped), hours format (48h).