AsyncRequest.php
1 year ago
AsyncWebhookService.php
9 months ago
BackgroundProcess.php
7 months ago
BackgroundServiceProvider.php
1 year ago
BulkActionService.php
6 months ago
Job.php
1 year ago
QueueService.php
2 months ago
Job.php
89 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SureCart\Background; |
| 4 | |
| 5 | /** |
| 6 | * Abstract Job class. |
| 7 | * |
| 8 | * @abstract |
| 9 | * @extends BackgroundProcess |
| 10 | */ |
| 11 | abstract class Job extends BackgroundProcess { |
| 12 | /** |
| 13 | * The next background process in the chain. |
| 14 | * |
| 15 | * @var BackgroundProcess |
| 16 | */ |
| 17 | protected $next = null; |
| 18 | |
| 19 | /** |
| 20 | * The task. |
| 21 | * |
| 22 | * @var \SureCart\Sync\Tasks\Task |
| 23 | */ |
| 24 | protected $task; |
| 25 | |
| 26 | /** |
| 27 | * Constructor. |
| 28 | * |
| 29 | * @param \SureCart\Sync\Tasks\Task $task The task. |
| 30 | */ |
| 31 | public function __construct( $task ) { |
| 32 | parent::__construct(); |
| 33 | $this->task = $task; |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Bootstrap the background process. |
| 38 | * |
| 39 | * @return void |
| 40 | */ |
| 41 | public function bootstrap() { |
| 42 | // we need to fake the dispatch method here because ajax handlers are only available in the constructor. |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Job complete. |
| 47 | * |
| 48 | * @return void |
| 49 | */ |
| 50 | protected function complete() { |
| 51 | parent::complete(); |
| 52 | |
| 53 | // run the next job in the chain. |
| 54 | if ( is_a( $this->next, self::class ) ) { |
| 55 | $this->next->dispatch(); |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Set the next background process in the chain. |
| 61 | * |
| 62 | * @param BackgroundProcess $next The next background process. |
| 63 | * |
| 64 | * @return $this |
| 65 | */ |
| 66 | public function setNext( $next ) { |
| 67 | $this->next = $next; |
| 68 | return $this; |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Get the task. |
| 73 | * |
| 74 | * @return \SureCart\Sync\Tasks\Task |
| 75 | */ |
| 76 | public function getTask() { |
| 77 | return $this->task; |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Is running. |
| 82 | * |
| 83 | * @return boolean |
| 84 | */ |
| 85 | public function isRunning() { |
| 86 | return $this->is_active() || $this->task->showNotice(); |
| 87 | } |
| 88 | } |
| 89 |