diff --git a/src/app/Jobs/CommonJob.php b/src/app/Jobs/CommonJob.php index fa9d0831..83a47e9f 100644 --- a/src/app/Jobs/CommonJob.php +++ b/src/app/Jobs/CommonJob.php @@ -1,140 +1,142 @@ handle(); * ``` */ abstract class CommonJob implements ShouldQueue { use Dispatchable; use InteractsWithQueue; use Queueable; /** * The failure message. * * @var string */ public $failureMessage; /** * The job deleted state. * * @var bool */ protected $isDeleted = false; /** * The job released state. * * @var bool */ protected $isReleased = false; /** * The number of tries for this Job. * * @var int */ public $tries = 5; /** * Execute the job. * * @return void */ abstract public function handle(); /** * Delete the job from the queue. * * @return void */ public function delete() { // We need this for testing purposes $this->isDeleted = true; // @phpstan-ignore-next-line if ($this->job) { $this->job->delete(); } } /** * Delete the job, call the "failed" method, and raise the failed job event. * * @param \Throwable|null $e An Exception * * @return void */ public function fail($e = null) { // Save the message, for testing purposes $this->failureMessage = $e->getMessage(); // @phpstan-ignore-next-line if ($this->job) { $this->job->fail($e); } } /** * Check if the job has failed * * @return bool */ public function hasFailed(): bool { return $this->failureMessage !== null; } /** * Release the job back into the queue. * * @param int $delay Time in seconds * @return void */ public function release($delay = 0) { // We need this for testing purposes $this->isReleased = true; // @phpstan-ignore-next-line if ($this->job) { $this->job->release($delay); + } else { + throw new \Exception("Attempted to release a manually executed job"); } } /** * Determine if the job has been deleted. * * @return bool */ public function isDeleted(): bool { return $this->isDeleted; } /** * Check if the job was released * * @return bool */ public function isReleased(): bool { return $this->isReleased; } }