scheduler = $scheduler; } /** * Whether new preview fan-out should wait. * * @return array{blocked:bool,reason?:string,pending:int,oldest_age_s:?int} */ public function assess() { if ( ! $this->scheduler ) { return array( 'blocked' => false, 'pending' => 0, 'oldest_age_s' => null, ); } $health = $this->scheduler->inspect_health( Constants::SCHEDULER_GROUP ); $pending = isset( $health['pending'] ) ? (int) $health['pending'] : 0; $oldest = isset( $health['oldest_pending_ts'] ) ? $health['oldest_pending_ts'] : null; $age = null; if ( null !== $oldest ) { $age = max( 0, time() - (int) $oldest ); } if ( $pending >= self::SOFT_PENDING_COUNT ) { return array( 'blocked' => true, 'reason' => sprintf( /* translators: %d: pending count */ __( 'Queue pressure: %d pending MarginBeacon jobs. Finish realtime evaluations before Recent Orders Preview.', 'marginbeacon' ), $pending ), 'pending' => $pending, 'oldest_age_s' => $age, ); } if ( null !== $age && $age >= self::SOFT_OLDEST_AGE_S ) { return array( 'blocked' => true, 'reason' => __( 'Queue pressure: oldest pending job is older than 15 minutes. Preview is deferred so new orders stay first.', 'marginbeacon' ), 'pending' => $pending, 'oldest_age_s' => $age, ); } return array( 'blocked' => false, 'pending' => $pending, 'oldest_age_s' => $age, ); } }