PluginProbe ʕ •ᴥ•ʔ
Hostinger Reach – AI-Powered Email Marketing for WordPress / 1.5.9
Hostinger Reach – AI-Powered Email Marketing for WordPress v1.5.9
1.6.0 1.5.9 1.5.8 1.5.7 1.5.6 1.5.5 1.5.4 1.5.3 1.5.2 1.5.1 1.5.0 1.4.12 1.4.11 1.4.10 1.4.9 1.4.8 1.4.7 trunk 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6
hostinger-reach / src / Jobs / AbstractJob.php
hostinger-reach / src / Jobs Last commit date
AbandonedCartsJob.php 7 months ago AbstractBatchedJob.php 7 months ago AbstractJob.php 5 months ago ActionScheduler.php 7 months ago CleanupCartsJob.php 2 weeks ago ImportJob.php 7 months ago JobInterface.php 8 months ago RecurringJobInterface.php 8 months ago
AbstractJob.php
69 lines
1 <?php
2 declare( strict_types=1 );
3
4 namespace Hostinger\Reach\Jobs;
5
6 use ActionScheduler_QueueRunner;
7 use Hostinger\Reach\Api\Handlers\ReachApiHandler;
8
9 defined( 'ABSPATH' ) || exit;
10
11 abstract class AbstractJob implements JobInterface {
12
13 protected ActionScheduler $action_scheduler;
14 protected ReachApiHandler $reach_api_handler;
15
16 public function __construct( ActionScheduler $action_scheduler, ReachApiHandler $reach_api_handler ) {
17 $this->action_scheduler = $action_scheduler;
18 $this->reach_api_handler = $reach_api_handler;
19 }
20
21 public function init(): void {
22 add_action( $this->get_process_item_hook(), array( $this, 'handle_process_items_action' ) );
23 add_action( $this->get_start_hook(), array( $this, 'handle_sart_hook_action' ) );
24
25 if ( $this instanceof RecurringJobInterface && $this->can_schedule_recurrent() ) {
26 $this->action_scheduler->schedule_recurring( $this->get_interval(), $this->get_start_hook() );
27 }
28 }
29
30 public function can_schedule_recurrent(): bool {
31 return ! $this->action_scheduler->has_scheduled_action( $this->get_start_hook() );
32 }
33
34 public function can_schedule( array $args = array() ): bool {
35 return $this->reach_api_handler->is_connected() && ! $this->is_running( $args );
36 }
37
38 public function handle_sart_hook_action( array $args = array() ): void {
39 $this->schedule( $args );
40 if ( class_exists( 'ActionScheduler_QueueRunner' ) ) {
41 ActionScheduler_QueueRunner::instance()->run();
42 }
43 }
44
45 public function handle_process_items_action( array $args = array() ): void {
46 $this->process_items( $args );
47 }
48
49 public function get_process_item_hook(): string {
50 return "{$this->get_hook_base_name()}/process_item";
51 }
52
53 public function get_start_hook(): string {
54 return "{$this->get_hook_base_name()}/start";
55 }
56
57 protected function is_running( ?array $args = array() ): bool {
58 return $this->action_scheduler->has_scheduled_action( $this->get_process_item_hook(), array( $args ) );
59 }
60
61 protected function get_hook_base_name(): string {
62 return "{$this->action_scheduler->get_group()}/jobs/{$this->get_name()}";
63 }
64
65 abstract public function get_name(): string;
66
67 abstract protected function process_items( array $args ): void;
68 }
69