$schedules * @return array */ public function schedules(array $schedules): array { if (!isset($schedules['wpwand_minutely'])) { $schedules['wpwand_minutely'] = [ 'interval' => 60, 'display' => __('Every minute (WP Wand)', 'ai-content-generation'), ]; } return $schedules; } public function cron_tick(): void { $runner = new JobRunner(); $start = time(); while ($runner->is_running() && (time() - $start) < self::BUDGET) { $res = $runner->tick(); // The provider asked for a pause. A tick during it returns at once, so without this the // loop would spin on the database for the rest of the budget. $wait = (int) ($res['waiting'] ?? 0); if ($wait > 0) { if ($wait >= self::BUDGET - (time() - $start)) { break; // longer than this run has left; the next cron run picks it up } sleep($wait); } } if (!$runner->is_running()) { $ts = wp_next_scheduled(self::HOOK); if ($ts) { wp_unschedule_event($ts, self::HOOK); } } } }