Fix AS init timing error in SystemAgentServiceProvider#1019
Merged
Conversation
Defer manageDailyMemorySchedule() to the action_scheduler_init hook instead of calling AS functions directly from the constructor at plugins_loaded. The constructor fires at plugins_loaded p20, before AS initializes its data store at init p1. This was the sole remaining source of the 'as_next_scheduled_action() was called before the Action Scheduler data store was initialized' notices that fire in massive clusters (50-100+ per ~20s) across all 10 subsites during cron/CLI operations. All 8 other DM files that interact with AS scheduling already use the action_scheduler_init pattern correctly.
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
manageDailyMemorySchedule()to theaction_scheduler_inithook instead of calling AS functions directly from the constructor atplugins_loadedpriority 20as_next_scheduled_action() was called before the Action Scheduler data store was initializednotices that fire in massive clusters (50-100+ per ~20s) across all 10 subsitesRoot Cause
SystemAgentServiceProvideris constructed atplugins_loadedp20 (viadatamachine_run_datamachine_plugin()). Its constructor callsmanageDailyMemorySchedule(), which callsas_next_scheduled_action()directly. At that point, the AS functions exist (files are loaded), but the data store isn't initialized untilaction_scheduler_initfires atinitp1.This was the only DM class doing it wrong — all 8 other files that interact with AS scheduling (
ActionsCleanup,ClaimsCleanup,CompletedJobsCleanup,JobsCleanup,LogCleanup,ProcessedItemsCleanup,FileCleanup,Chat) already correctly defer toaction_scheduler_init.Fix
Wrap the scheduling logic in
add_action('action_scheduler_init', ...)— same pattern used everywhere else.