We had some cases of multiple triggers created most probably because of a race conditions. The unique action functionality added in the action scheduled 3.5.0 should prevent it. [MAILPOET-4684]
26 lines
910 B
PHP
26 lines
910 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 = [], bool $unique = true): int {
|
|
return as_schedule_recurring_action($timestamp, $interval_in_seconds, $hook, $args, self::GROUP_ID, $unique);
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|