AbandonedCartsJob.php
6 months ago
AbstractBatchedJob.php
6 months ago
AbstractJob.php
3 months ago
ActionScheduler.php
5 months ago
CleanupCartsJob.php
6 months ago
ImportJob.php
5 months ago
JobInterface.php
7 months ago
RecurringJobInterface.php
7 months ago
ActionScheduler.php
50 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Hostinger\Reach\Jobs; |
| 4 | |
| 5 | defined( 'ABSPATH' ) || exit; |
| 6 | |
| 7 | class ActionScheduler { |
| 8 | |
| 9 | public const STATUS_PENDING = 'pending'; |
| 10 | public const STATUS_COMPLETE = 'complete'; |
| 11 | public const STATUS_FAILED = 'failed'; |
| 12 | |
| 13 | public function get_group(): string { |
| 14 | return defined( 'HOSTINGER_REACH_PLUGIN_SLUG' ) ? HOSTINGER_REACH_PLUGIN_SLUG : 'hostinger-reach'; |
| 15 | } |
| 16 | |
| 17 | public function schedule_recurring( int $interval, string $hook, array $args = array() ): int { |
| 18 | if ( ! function_exists( 'as_schedule_recurring_action' ) ) { |
| 19 | return 0; |
| 20 | } |
| 21 | |
| 22 | $group = $this->get_group(); |
| 23 | return as_schedule_recurring_action( gmdate( 'U' ), $interval, $hook, $args, $group, true ); |
| 24 | } |
| 25 | |
| 26 | public function schedule_single( int $timestamp, string $hook, array $args = array() ): int { |
| 27 | if ( ! function_exists( 'as_schedule_single_action' ) ) { |
| 28 | return 0; |
| 29 | } |
| 30 | |
| 31 | return as_schedule_single_action( $timestamp, $hook, $args, $this->get_group() ); |
| 32 | } |
| 33 | |
| 34 | public function schedule_immediate( string $hook, array $args = array() ): int { |
| 35 | if ( ! function_exists( 'as_schedule_single_action' ) ) { |
| 36 | return 0; |
| 37 | } |
| 38 | |
| 39 | return as_schedule_single_action( gmdate( 'U' ), $hook, $args, $this->get_group() ); |
| 40 | } |
| 41 | |
| 42 | public function has_scheduled_action( string $hook, array $args = array() ): bool { |
| 43 | if ( ! function_exists( 'as_next_scheduled_action' ) ) { |
| 44 | return false; |
| 45 | } |
| 46 | |
| 47 | return as_next_scheduled_action( $hook, $args, $this->get_group() ) !== false; |
| 48 | } |
| 49 | } |
| 50 |