diff --git a/plugins/data-machine/docs/core-system/routines-scheduling.md b/plugins/data-machine/docs/core-system/routines-scheduling.md index dca56e9007..e4fba01a06 100644 --- a/plugins/data-machine/docs/core-system/routines-scheduling.md +++ b/plugins/data-machine/docs/core-system/routines-scheduling.md @@ -7,14 +7,18 @@ single-flight scheduling, and drift repair. ## Identity contract -| | Before (bespoke scheduler) | After (routines) | -|---|---|---| -| Hook | `datamachine_run_flow_now` | `wp_agent_routine_run_scheduled` | -| Args | `[flow_id, null, {generation}]` | `['routine_id' => 'flow-N']` | -| Group | `data-machine` | `agents-api` | -| Fencing | DM generation options | substrate generations (`agents_routine_generation_`) | -| One-time | single action, same hook | single action under `datamachine_run_flow_once` (group `data-machine`) | -| Reconcile | `FlowScheduleReconciler` + lock | `Registry::reconcile()` via `FlowRoutines::reconcile()` | +| | Routines | +|---|---| +| Hook | `wp_agent_routine_run_scheduled` | +| Args | `['routine_id' => 'flow-N']` | +| Group | `agents-api` | +| Fencing | substrate generations (`agents_routine_generation_`) | +| One-time | single action under `datamachine_run_flow_once` (group `data-machine`) | +| Reconcile | `Registry::reconcile()` via `FlowRoutines::reconcile()` | + +`datamachine_run_flow_now` is not a scheduling hook: it carries one-off wakes +(`[flow_id]` / `[flow_id, job_id]`) from queue backpressure deferrals and +stuck-job recovery. ## How it works @@ -45,20 +49,9 @@ single-flight scheduling, and drift repair. actually registered this request, targeting `datamachine/run-flow` or `datamachine/dispatch-system-task`. -## Migration - -Boot does not cancel legacy generated actions (hook `datamachine_run_flow_now`, -args `[flow_id, null, {generation}]`). Use the explicit migration command to -inspect and cancel them: +## Reconcile ```bash -wp datamachine flows migrate-routines # dry run: prints the plan -wp datamachine flows migrate-routines --apply # cancel legacy chains now wp datamachine flows reconcile-schedules # audit routine coverage wp datamachine flows reconcile-schedules --apply # repair missing coverage ``` - -First runs after the migration shift by up to `min(interval, 3600)`s because -the substrate staggers the new chains deterministically per routine id. -`datamachine_run_flow_now` remains a live hook for queue backpressure deferral -ticks and is scheduled to retire one release after this migration. diff --git a/plugins/data-machine/inc/Abilities/Engine/ScheduleFlowAbility.php b/plugins/data-machine/inc/Abilities/Engine/ScheduleFlowAbility.php index 076ef0efd6..f6c9f0467e 100644 --- a/plugins/data-machine/inc/Abilities/Engine/ScheduleFlowAbility.php +++ b/plugins/data-machine/inc/Abilities/Engine/ScheduleFlowAbility.php @@ -180,7 +180,7 @@ private function scheduleOneTime( int $flow_id, int $timestamp ): array|\WP_Erro array( 'hook' => FlowRoutines::ONE_TIME_HOOK, 'args' => array( 'flow_id' => $flow_id ), - 'group' => FlowRoutines::LEGACY_GROUP, + 'group' => FlowRoutines::ONE_TIME_GROUP, 'status' => 'pending', 'per_page' => 1, ), diff --git a/plugins/data-machine/inc/Cli/Commands/Flows/FlowsCommand.php b/plugins/data-machine/inc/Cli/Commands/Flows/FlowsCommand.php index 2914e6383a..d6a22cdf03 100644 --- a/plugins/data-machine/inc/Cli/Commands/Flows/FlowsCommand.php +++ b/plugins/data-machine/inc/Cli/Commands/Flows/FlowsCommand.php @@ -374,81 +374,6 @@ public function reconcile_schedules( array $args, array $assoc_args ): void { } } - /** - * Show (or run) the one-shot legacy schedule migration. - * - * ## OPTIONS - * - * [--apply] - * : Cancel the legacy pending actions. Without it this is a dry-run. - * - * [--dry-run] - * : Legacy flag. Like --apply, it runs the migration (kept for compatibility). - * - * [--format=] - * : Output format: table or json. - * --- - * default: table - * --- - * - * ## EXAMPLES - * - * wp datamachine flows migrate-routines - * wp datamachine flows migrate-routines --apply - * - * @subcommand migrate-routines - */ - public function migrate_routines( array $args, array $assoc_args ): void { - $dry_run = ! isset( $assoc_args['dry-run'] ) && ! isset( $assoc_args['apply'] ); - - $plan = \DataMachine\Engine\Scheduling\FlowRoutines::migrate_legacy_schedules( $dry_run ); - - $format = (string) ( $assoc_args['format'] ?? 'table' ); - if ( 'json' === $format ) { - WP_CLI::line( (string) wp_json_encode( $plan, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES ) ); - if ( ! empty( $plan['errors'] ) ) { - WP_CLI::halt( 1 ); - } - return; - } - - WP_CLI::log( $dry_run ? 'Mode: dry-run' : 'Mode: apply' ); - WP_CLI::log( - sprintf( - 'Legacy pending actions: %d | Cancelled: %d | Errors: %d', - (int) ( $plan['legacy_actions'] ?? 0 ), - (int) ( $plan['cancelled'] ?? 0 ), - count( (array) ( $plan['errors'] ?? array() ) ) - ) - ); - - $flows = array_slice( (array) ( $plan['flows'] ?? array() ), 0, 50 ); - if ( ! empty( $flows ) ) { - WP_CLI\Utils\format_items( - 'table', - array_map( - static fn( $entry ) => array( - 'flow_id' => (int) ( $entry['flow_id'] ?? 0 ), - 'routine_id' => (string) ( $entry['routine_id'] ?? '' ), - 'old_actions' => count( (array) ( $entry['legacy_action_ids'] ?? array() ) ), - 'cancelled' => ! empty( $entry['cancelled'] ) ? 'yes' : ( $dry_run ? 'planned' : 'no' ), - ), - $flows - ), - array( 'flow_id', 'routine_id', 'old_actions', 'cancelled' ) - ); - if ( ! empty( $plan['details_truncated'] ) ) { - WP_CLI::warning( 'Detail output was truncated; use --format=json for the full plan.' ); - } - } - - if ( ! empty( $plan['errors'] ) ) { - WP_CLI::error( 'Migration completed with errors; rerun to retry.' ); - } - - WP_CLI::success( $dry_run ? 'Dry run complete. Rerun with --apply to cancel the legacy actions.' : 'Migration applied.' ); - } - /** * Diagnose or explicitly repair literal JSON solidus escapes in one flow. * diff --git a/plugins/data-machine/inc/Core/Jobs/SchedulerEvidence.php b/plugins/data-machine/inc/Core/Jobs/SchedulerEvidence.php index 134945b3e5..390569f5e1 100644 --- a/plugins/data-machine/inc/Core/Jobs/SchedulerEvidence.php +++ b/plugins/data-machine/inc/Core/Jobs/SchedulerEvidence.php @@ -26,7 +26,6 @@ use DataMachine\Core\DirectJobEnqueuer; use DataMachine\Engine\AI\AIConcurrencyBackpressure; use DataMachine\Engine\AI\System\Tasks\SystemTask; -use DataMachine\Engine\Scheduling\FlowRoutines; use DataMachine\Engine\Tasks\TaskScheduler; defined( 'ABSPATH' ) || exit; @@ -75,7 +74,7 @@ public static function hookJobArgs(): array { AIConcurrencyBackpressure::RESUME_HOOK => array( 'arg' => 'job_id' ), PipelineBatchScheduler::BATCH_HOOK => array( 'arg' => 'parent_job_id' ), TaskScheduler::BATCH_HOOK => array( 'arg' => 'parent_job_id' ), - FlowRoutines::LEGACY_HOOK => array( + 'datamachine_run_flow_now' => array( 'arg' => 'job_id', 'position' => 1, ), diff --git a/plugins/data-machine/inc/Engine/Actions/Engine.php b/plugins/data-machine/inc/Engine/Actions/Engine.php index a7b69ca0f1..b93e006223 100644 --- a/plugins/data-machine/inc/Engine/Actions/Engine.php +++ b/plugins/data-machine/inc/Engine/Actions/Engine.php @@ -145,32 +145,6 @@ function datamachine_dispatch_run_flow( $flow_id, $job_id = null ): void { } } -/** - * Bridge for the legacy datamachine_run_flow_now hook. - * - * Positional wakes (`[ flow_id ]`, `[ flow_id, job_id ]`) from backpressure - * deferrals and stuck-job recovery still dispatch. A legacy recurring action - * carries the schedule generation marker at args[2]; after the routines - * migration those must not run, or they would double-fire beside the - * routine. TODO(3458): drop the legacy branch after one release. - * - * @param int $flow_id Flow ID. - * @param mixed $job_id Optional pre-created job ID. - * @param mixed $schedule_generation Legacy generation marker, if any. - */ -function datamachine_dispatch_scheduled_flow_wake( $flow_id, $job_id = null, $schedule_generation = null ): void { - if ( null !== $schedule_generation ) { - do_action( - 'datamachine_log', - 'warning', - 'Legacy recurring schedule action ignored after routines migration', - array( 'flow_id' => (int) $flow_id ) - ); - return; - } - datamachine_dispatch_run_flow( $flow_id, $job_id ); -} - /** Validate durable resume ownership before entering canonical step execution. */ function datamachine_resume_ai_step_action( $job_id, string $flow_step_id, $operation_generation = 0, $operation_claim_token = '', $ai_resume_generation = 0 ): void { $job_id = (int) $job_id; @@ -262,19 +236,15 @@ static function ( $code, $context = array() ): void { /** * Bridge: datamachine_run_flow_now → datamachine/run-flow ability. * - * Still a live execution path for one-off wakes: queue backpressure - * deferrals and stuck-job recovery re-runs schedule this hook with - * positional args `[ flow_id ]` / `[ flow_id, job_id ]`. Recurring - * schedules moved to Agents API Routines; a legacy recurring action - * (identified by the generation marker at args[2]) that is still pending - * after migration is ignored and logged so it cannot double-fire beside - * its routine. TODO(3458): drop the legacy branch after one release. + * One-off wakes: queue backpressure deferrals and stuck-job recovery + * re-runs schedule this hook with positional args `[ flow_id ]` / + * `[ flow_id, job_id ]`. */ add_action( 'datamachine_run_flow_now', - 'datamachine_dispatch_scheduled_flow_wake', + 'datamachine_dispatch_run_flow', 10, - 3 + 2 ); /** diff --git a/plugins/data-machine/inc/Engine/Scheduling/FlowRoutines.php b/plugins/data-machine/inc/Engine/Scheduling/FlowRoutines.php index 5a2fcdb001..1df2fbcf5c 100644 --- a/plugins/data-machine/inc/Engine/Scheduling/FlowRoutines.php +++ b/plugins/data-machine/inc/Engine/Scheduling/FlowRoutines.php @@ -9,10 +9,8 @@ * One-time flow runs stay as plain Action Scheduler single actions under * `datamachine_run_flow_once` — routines are recurring by definition. * - * Identity contract (old → new): - * - hook `datamachine_run_flow_now`, args `[flow_id, null, generation]`, - * group `data-machine` → hook `wp_agent_routine_run_scheduled`, - * args `['routine_id' => 'flow-N']`, group `agents-api`. + * Identity contract: recurring wakes use hook `wp_agent_routine_run_scheduled`, + * args `['routine_id' => 'flow-N']`, group `agents-api`. * * `boot()` runs on every request that loads the full runtime: the routine * registry is in-memory by design, so persisted flows and schedules are @@ -56,30 +54,15 @@ final class FlowRoutines { */ public const ROUTINE_GROUP = 'agents-api'; - /** - * Legacy recurring hook; still a live execution path for queue - * backpressure deferrals and straggler actions until one release after - * this migration. - * - * TODO(3458): retire this hook's remaining uses one release after the - * routines migration ships. - */ - public const LEGACY_HOOK = 'datamachine_run_flow_now'; - /** * Action Scheduler hook for one-time (timestamp) flow runs. */ public const ONE_TIME_HOOK = 'datamachine_run_flow_once'; /** - * Data Machine's own Action Scheduler group (legacy actions + one_time). - */ - public const LEGACY_GROUP = GroupRegistrar::GROUP; - - /** - * Option marking the one-shot legacy-action migration as done. + * Action Scheduler group for one-time flow runs (Data Machine's own group). */ - public const MIGRATED_OPTION = 'datamachine_routines_migrated_v1'; + public const ONE_TIME_GROUP = GroupRegistrar::GROUP; /** * Wake target for flow routines. @@ -416,7 +399,7 @@ public static function next_run( int $flow_id ): ?string { $timestamp = as_next_scheduled_action( self::ONE_TIME_HOOK, array( 'flow_id' => $flow_id ), - self::LEGACY_GROUP + self::ONE_TIME_GROUP ); } @@ -458,7 +441,6 @@ public static function next_runs( array $flow_ids ): array { * * Runs on `init` of every full-runtime request. Reads desired schedules * from the flow table; matching schedule records bypass Action Scheduler. - * Legacy schedule conversion runs via `wp datamachine flows migrate-routines`. * * Per-routine registration is isolated with its own try/catch (see * {@see register_routine_logged()}) so one bad routine does not stop the @@ -507,7 +489,7 @@ public static function boot(): void { if ( ! self::system_schedule_active( $schedule ) ) { // Clear a previously minted schedule on disable, even if the // registry is empty in this request. Without a generation, leave - // any legacy orphan for the hourly pass instead of querying AS. + // any stray action for the hourly pass instead of querying AS. if ( is_wp_error( WP_Agent_Routine_Registry::unregister( $routine_id ) ) && null !== self::current_generation( $routine_id ) ) { WP_Agent_Routine_Registry::backend()?->unregister( $routine_id ); } @@ -793,116 +775,6 @@ public static function reconcile( bool $apply = false ): array { ); } - /** - * Build the migration/cancellation plan for legacy generated actions. - * - * Legacy recurring chains live under `datamachine_run_flow_now` with the - * generated three-element args shape `[flow_id, null, {generation}]`. - * Single-argument actions (queue backpressure deferrals) are never - * touched — they are transient execution ticks, not recurring chains. - * - * @param bool $dry_run Report the plan without cancelling anything. - * @return array Per-flow plan. - */ - public static function migrate_legacy_schedules( bool $dry_run = false ): array { - $plan = array( - 'dry_run' => $dry_run, - 'legacy_actions' => 0, - 'cancelled' => 0, - 'flows' => array(), - 'details_truncated' => false, - 'errors' => array(), - ); - - if ( ! function_exists( 'as_get_scheduled_actions' ) || ! class_exists( '\ActionScheduler_Store' ) ) { - $plan['errors']['_action_scheduler'] = 'Action Scheduler is unavailable.'; - return $plan; - } - - $ids = as_get_scheduled_actions( - array( - 'hook' => self::LEGACY_HOOK, - 'group' => self::LEGACY_GROUP, - 'status' => \ActionScheduler_Store::STATUS_PENDING, - 'per_page' => -1, - ), - 'ids' - ); - - $by_flow = array(); - foreach ( $ids as $id ) { - $action_id = (int) $id; - if ( $action_id <= 0 ) { - continue; - } - - try { - $action = \ActionScheduler_Store::instance()->fetch_action( (string) $action_id ); - } catch ( \Throwable $error ) { - unset( $error ); - continue; - } - - $args = $action->get_args(); - $flow_id = isset( $args[0] ) ? (int) $args[0] : 0; - - if ( $flow_id <= 0 || ! isset( $args[2] ) || ! is_array( $args[2] ) ) { - // Not a generated recurring chain (e.g. a backpressure - // deferral tick with args `[flow_id]`): leave it alone. - continue; - } - - $by_flow[ $flow_id ][] = $action_id; - } - - $plan['legacy_actions'] = array_sum( array_map( 'count', $by_flow ) ); - - foreach ( $by_flow as $flow_id => $action_ids ) { - $entry = array( - 'flow_id' => $flow_id, - 'routine_id' => self::routine_id( $flow_id ), - 'legacy_action_ids' => $action_ids, - 'cancelled' => false, - ); - - if ( ! $dry_run ) { - foreach ( $action_ids as $action_id ) { - try { - \ActionScheduler_Store::instance()->cancel_action( (string) $action_id ); - ++$plan['cancelled']; - } catch ( \Throwable $error ) { - unset( $error ); - $plan['errors'][ 'action_' . $action_id ] = 'Failed to cancel the legacy action.'; - } - } - - $entry['cancelled'] = count( $action_ids ) === count( - array_filter( $action_ids, static fn( $id ) => ! in_array( 'action_' . $id, array_keys( $plan['errors'] ), true ) ) - ); - } - - if ( count( $plan['flows'] ) < 2000 ) { - $plan['flows'][] = $entry; - } else { - $plan['details_truncated'] = true; - } - } - - if ( ! $dry_run && array() === $plan['errors'] ) { - update_option( - self::MIGRATED_OPTION, - array( - 'migrated_at' => time(), - 'legacy_actions' => $plan['legacy_actions'], - 'flows' => count( $plan['flows'] ), - ), - false - ); - } - - return $plan; - } - /** * Detect whether a value looks like a cron expression. * @@ -1120,7 +992,7 @@ private static function cancel_one_time( int $flow_id ): void { return; } - as_unschedule_all_actions( self::ONE_TIME_HOOK, array( 'flow_id' => $flow_id ), self::LEGACY_GROUP ); + as_unschedule_all_actions( self::ONE_TIME_HOOK, array( 'flow_id' => $flow_id ), self::ONE_TIME_GROUP ); } /** @@ -1178,7 +1050,7 @@ public static function enqueue_one_time( int $flow_id, int $timestamp ): int|\WP $timestamp, self::ONE_TIME_HOOK, array( 'flow_id' => $flow_id ), - self::LEGACY_GROUP + self::ONE_TIME_GROUP ); if ( ! $action_id ) { return new \WP_Error( 'schedule_failed', 'The one-time run could not be scheduled.', array( @@ -1275,7 +1147,7 @@ private static function has_live_coverage( int $flow_id ): bool { $one_time = as_next_scheduled_action( self::ONE_TIME_HOOK, array( 'flow_id' => $flow_id ), - self::LEGACY_GROUP + self::ONE_TIME_GROUP ); return is_int( $one_time ) && $one_time > 0; diff --git a/plugins/data-machine/inc/setup/schema.php b/plugins/data-machine/inc/setup/schema.php index 2df45b547e..084b903db0 100644 --- a/plugins/data-machine/inc/setup/schema.php +++ b/plugins/data-machine/inc/setup/schema.php @@ -136,13 +136,6 @@ function datamachine_run_deferred_site_setup(): void { \DataMachine\Core\Bootstrap\ActivationServiceProvider::register_capabilities(); \DataMachine\Core\Bootstrap\ActivationServiceProvider::activate_defaults_for_site(); - // One-shot cleanup (Extra-Chill/data-machine#3497): the hash-gated - // routine backend decorator that wrote this option was removed once the - // Agents API Action Scheduler bridge's own register() became idempotent - // (wordpress/agents-api v0.11.1). delete_option() on an already-absent - // row is a cheap no-op, so this is safe to run on every version bump. - delete_option( 'datamachine_routine_schedule_hashes' ); - datamachine_drop_legacy_chat_sessions(); datamachine_migrate_legacy_mode_models(); } diff --git a/plugins/data-machine/tests/Unit/Engine/Scheduling/FlowRoutinesTest.php b/plugins/data-machine/tests/Unit/Engine/Scheduling/FlowRoutinesTest.php index 6217640d92..fc9fa85117 100644 --- a/plugins/data-machine/tests/Unit/Engine/Scheduling/FlowRoutinesTest.php +++ b/plugins/data-machine/tests/Unit/Engine/Scheduling/FlowRoutinesTest.php @@ -1,8 +1,7 @@ user->create( array( 'role' => 'administrator' ) ) ); - delete_option( FlowRoutines::MIGRATED_OPTION ); $pipeline = wp_get_ability( 'datamachine/create-pipeline' )->execute( array( 'pipeline_name' => 'Routines adapter' ) ); $this->pipeline_id = (int) $pipeline['pipeline_id']; } @@ -46,7 +44,6 @@ public function tear_down(): void { } } WP_Agent_Routine_Registry::reset(); - delete_option( FlowRoutines::MIGRATED_OPTION ); parent::tear_down(); } @@ -125,92 +122,6 @@ public function test_permission_filter_allows_owned_flow_routines_and_denies_oth $this->assertFalse( FlowRoutines::filter_ability_permission( false, $cross_target, null ), 'Routine ids may not execute abilities outside the allow-list.' ); } - public function test_migration_dry_run_reports_plan_without_cancelling(): void { - $flow_id = $this->create_flow( 'Migration flow' ); - $this->assertTrue( FlowRoutines::sync( $flow_id, array( 'interval' => 'hourly' ) ) ); - - $legacy_id = as_schedule_single_action( - time() + HOUR_IN_SECONDS, - 'datamachine_run_flow_now', - array( $flow_id, null, array( '_datamachine_schedule_generation' => wp_generate_uuid4() ) ), - 'data-machine' - ); - $this->assertGreaterThan( 0, $legacy_id ); - - $plan = FlowRoutines::migrate_legacy_schedules( true ); - - $this->assertTrue( $plan['dry_run'] ); - $this->assertSame( 1, (int) $plan['legacy_actions'], 'Dry run must report the legacy pending action.' ); - $this->assertSame( 0, (int) $plan['cancelled'], 'Dry run must not cancel anything.' ); - - $planned = array_column( $plan['flows'], null, 'flow_id' ); - $this->assertArrayHasKey( $flow_id, $planned, 'Plan must map the flow to its legacy action.' ); - $this->assertSame( FlowRoutines::routine_id( $flow_id ), $planned[ $flow_id ]['routine_id'] ); - $this->assertSame( array( (int) $legacy_id ), $planned[ $flow_id ]['legacy_action_ids'] ); - $this->assertFalse( (bool) $planned[ $flow_id ]['cancelled'] ); - - $this->assertGreaterThan( 0, $this->legacy_action_pending( (int) $legacy_id ), 'Dry run must leave the legacy action pending.' ); - $this->assertFalse( get_option( FlowRoutines::MIGRATED_OPTION ), 'Dry run must not set the migrated marker.' ); - } - - public function test_migration_apply_cancels_generated_chains_only(): void { - $flow_id = $this->create_flow( 'Migration apply flow' ); - $this->assertTrue( FlowRoutines::sync( $flow_id, array( 'interval' => 'hourly' ) ) ); - - $legacy_id = as_schedule_single_action( - time() + HOUR_IN_SECONDS, - 'datamachine_run_flow_now', - array( $flow_id, null, array( '_datamachine_schedule_generation' => wp_generate_uuid4() ) ), - 'data-machine' - ); - $deferral_id = as_schedule_single_action( - time() + 60, - 'datamachine_run_flow_now', - array( $flow_id ), - 'data-machine' - ); - - $plan = FlowRoutines::migrate_legacy_schedules( false ); - - $this->assertFalse( $plan['dry_run'] ); - $this->assertSame( 1, (int) $plan['cancelled'], 'Apply must cancel exactly the generated chain.' ); - $this->assertSame( 0, $this->legacy_action_pending( (int) $legacy_id ), 'Generated chain action must be cancelled.' ); - $this->assertGreaterThan( 0, $this->legacy_action_pending( (int) $deferral_id ), 'Backpressure deferral ticks must survive migration.' ); - - $marker = get_option( FlowRoutines::MIGRATED_OPTION ); - $this->assertIsArray( $marker, 'Apply must set the one-shot migrated marker.' ); - } - - public function test_legacy_recurring_wake_is_ignored_but_positional_wakes_still_dispatch(): void { - $flow_id = $this->create_flow( 'Legacy wake flow' ); - $executed = array(); - $spy = static function ( $name, $input ) use ( &$executed ): void { - if ( 'datamachine/run-flow' === $name ) { - $executed[] = (int) ( $input['flow_id'] ?? 0 ); - } - }; - add_action( 'wp_ability_invoked', $spy, 10, 2 ); - - $logged = array(); - $log = static function ( $level, $message ) use ( &$logged ): void { - $logged[] = array( $level, $message ); - }; - add_action( 'datamachine_log', $log, 10, 2 ); - - try { - // A stale generated chain (generation marker at args[2]) must not run. - do_action( 'datamachine_run_flow_now', $flow_id, null, array( '_datamachine_schedule_generation' => 'stale' ) ); - $this->assertSame( array(), $executed, 'Legacy recurring wake must not dispatch the flow.' ); - $this->assertNotEmpty( - array_filter( $logged, static fn( $entry ) => 'Legacy recurring schedule action ignored after routines migration' === $entry[1] ), - 'Ignored legacy wake must be logged.' - ); - } finally { - remove_action( 'wp_ability_invoked', $spy, 10 ); - remove_action( 'datamachine_log', $log, 10 ); - } - } - private function create_flow( string $name ): int { $result = wp_get_ability( 'datamachine/create-flow' )->execute( array( @@ -234,18 +145,4 @@ private function pending_routine_action_id( int $flow_id ): int { return is_int( $timestamp ) && $timestamp > 0 ? $timestamp : 0; } - - /** - * Whether one action id is still pending; returns its id when pending. - */ - private function legacy_action_pending( int $action_id ): int { - try { - $status = \ActionScheduler_Store::instance()->get_status( (string) $action_id ); - } catch ( \Throwable $throwable ) { - unset( $throwable ); - return 0; - } - - return \ActionScheduler_Store::STATUS_PENDING === $status ? $action_id : 0; - } } diff --git a/plugins/data-machine/tests/delayed-flow-preserves-schedule-smoke.php b/plugins/data-machine/tests/delayed-flow-preserves-schedule-smoke.php index fc9ed026b7..fd34dd86cd 100644 --- a/plugins/data-machine/tests/delayed-flow-preserves-schedule-smoke.php +++ b/plugins/data-machine/tests/delayed-flow-preserves-schedule-smoke.php @@ -83,7 +83,7 @@ public function __construct() { $this->initDatabases(); } $result = $ability->execute( array( 'flow_id' => $id, 'interval_or_timestamp' => (string) $timestamp ) ); check( is_array( $result ) && $result['success'] && 'one_time' === $result['schedule_type'], 'Ability must report a one-time run' ); check( Flows::$configs[$id] === $config, 'Delayed run must preserve all scheduling config' ); - check( $GLOBALS['actions'][$result['action_id']] === array( 'timestamp' => $timestamp, 'hook' => FlowRoutines::ONE_TIME_HOOK, 'args' => array( 'flow_id' => $id ), 'group' => FlowRoutines::LEGACY_GROUP ), 'Returned action must use the engine bridge contract at T' ); + check( $GLOBALS['actions'][$result['action_id']] === array( 'timestamp' => $timestamp, 'hook' => FlowRoutines::ONE_TIME_HOOK, 'args' => array( 'flow_id' => $id ), 'group' => FlowRoutines::ONE_TIME_GROUP ), 'Returned action must use the engine bridge contract at T' ); unset( $GLOBALS['actions'][$result['action_id']] ); // Single action consumed. JobCompleteHandler::handle( $id, 'completed' ); check( Flows::$configs[$id] === $config, 'Completion must preserve recurring config' );