-
Notifications
You must be signed in to change notification settings - Fork 328
Closed
Labels
P0High priorityHigh priorityPHPTeam SIssues for Squad 1Issues for Squad 1Type: EnhancementImprovement of an existing featureImprovement of an existing feature
Description
Feature Description
- Schedule a daily event using wp_schedule_event with daily recurrence
- Check if the feature is enabled. If so, check for missing frequency initiator events. If a missing event is found, then recreate it.
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
- A daily scheduled event automatically recreates any missing initiator schedules for weekly, monthly, and quarterly email reports using the existing schedule helpers added in Implement “Initiator” scheduled events #11546
- Monitor runs only when Email Reports is enabled; when disabled, or the plugin is reset or uninstalled, the scheduled event should be removed.
- Only missing schedules are restored; existing ones are left untouched.
Implementation Brief
- Extend
Core\Email_Reporting\Email_Reporting_Scheduler- Define a new action constant, e.g. const
ACTION_MONITOR = 'googlesitekit_email_reporting_monitor'. - Add a helper
schedule_monitor()that checkswp_next_scheduled( self::ACTION_MONITOR )and, if missing, registers a recurring event withwp_schedule_event( time(), 'daily', self::ACTION_MONITOR ). - Update
unschedule_all()to invokewp_unschedule_hook( self::ACTION_MONITOR )so the daily event is removed when the feature is disabled. - Ensure
ACTION_MONITORis added toUninstallation::SCHEDULED_EVENTS.
- Define a new action constant, e.g. const
- Create
Core\Email_Reporting\Monitor_Taskclass- It should accept
Email_Reporting_Schedulervia its constructor. - Implement
handle_monitor_action()- It should bail immediately when
Email_Reporting_Settings::is_email_reporting_enabled()returns false.
- It should bail immediately when
- For each supported frequency (
WEEKLY,MONTHLY,QUARTERLY), callwp_next_scheduled( Email_Reporting_Scheduler::ACTION_INITIATOR, array( $frequency ) ).- If it returns false, invoke
$scheduler->schedule_initiator_once( $frequency )(the method already checks for if the CRON is scheduled, so no need to do anything else besides invoking it)
- If it returns false, invoke
- It should accept
- Update
Google\Site_Kit\Core\Email_Reporting\Email_Reporting::register()- Within existing feature toggle listener - when the feature is enabled, call
$scheduler->schedule_monitor()in addition to the initial initiators. - Instantiate
Monitor_Task, and hook intoEmail_Reporting_Scheduler::ACTION_MONITORinvoking'handle_monitor_action'callback ofCore\Email_Reporting\Monitor_Task
- Within existing feature toggle listener - when the feature is enabled, call
Test Coverage
- Add basic test coverage for
Monitor_Task
QA Brief
- Enable the feature flag and install a plugin that lets you see WP scheduled events (like WP Crontrol).
- Toggle the feature in the admin settings, when the feature is enabled you should see a daily registered event:
googlesitekit_email_reporting_monitor
Changelog entry
- Implement monitor scheduler for Email Reporting events.
Metadata
Metadata
Assignees
Labels
P0High priorityHigh priorityPHPTeam SIssues for Squad 1Issues for Squad 1Type: EnhancementImprovement of an existing featureImprovement of an existing feature