Files
piratepoet/mailpoet/lib/Cron/ActionScheduler/ActionScheduler.php
Rostislav Wolny 4d7f6f8c75 Use more effective method deactivation
This will cancel all jobs with one query. Instead of cancelling one by one.
In case that some action gets scheduled multiple times e.g. due a race condition
it will remove all jobs.
2022-10-13 14:21:43 +02:00

26 lines
880 B
PHP

<?php declare(strict_types = 1);
namespace MailPoet\Cron\ActionScheduler;
class ActionScheduler {
public const GROUP_ID = 'mailpoet-cron';
public function scheduleRecurringAction(int $timestamp, int $interval_in_seconds, string $hook, array $args = []): int {
return as_schedule_recurring_action($timestamp, $interval_in_seconds, $hook, $args, self::GROUP_ID);
}
public function unscheduleAction(string $hook, array $args = []): ?int {
$id = as_unschedule_action($hook, $args, self::GROUP_ID);
return $id !== null ? intval($id) : null;
}
public function unscheduleAllCronActions(): void {
// Passing only group to unschedule all by group
as_unschedule_all_actions('', [], self::GROUP_ID);
}
public function hasScheduledAction(string $hook, array $args = []): bool {
return as_has_scheduled_action($hook, $args, self::GROUP_ID);
}
}