Changeset View
Changeset View
Standalone View
Standalone View
src/app/Jobs/DomainJob.php
<?php | <?php | ||||
namespace App\Jobs; | namespace App\Jobs; | ||||
use Illuminate\Bus\Queueable; | |||||
use Illuminate\Contracts\Queue\ShouldQueue; | |||||
use Illuminate\Foundation\Bus\Dispatchable; | |||||
use Illuminate\Queue\InteractsWithQueue; | |||||
/** | /** | ||||
* The abstract \App\Jobs\DomainJob implements the logic needed for all dispatchable Jobs related to | * The abstract \App\Jobs\DomainJob implements the logic needed for all dispatchable Jobs related to | ||||
* \App\Domain objects. | * \App\Domain objects. | ||||
* | * | ||||
* ```php | * ```php | ||||
* $job = new \App\Jobs\Domain\CreateJob($domainId); | * $job = new \App\Jobs\Domain\CreateJob($domainId); | ||||
* $job->handle(); | * $job->handle(); | ||||
* ``` | * ``` | ||||
*/ | */ | ||||
abstract class DomainJob implements ShouldQueue | abstract class DomainJob extends CommonJob | ||||
{ | { | ||||
use Dispatchable; | |||||
use InteractsWithQueue; | |||||
use Queueable; | |||||
/** | /** | ||||
* The ID for the \App\Domain. This is the shortest globally unique identifier and saves Redis space | * The ID for the \App\Domain. This is the shortest globally unique identifier and saves Redis space | ||||
* compared to a serialized version of the complete \App\Domain object. | * compared to a serialized version of the complete \App\Domain object. | ||||
* | * | ||||
* @var int | * @var int | ||||
*/ | */ | ||||
protected $domainId; | protected $domainId; | ||||
/** | /** | ||||
* The \App\Domain namespace property, for legibility in the queue management. | * The \App\Domain namespace property, for legibility in the queue management. | ||||
* | * | ||||
* @var string | * @var string | ||||
*/ | */ | ||||
protected $domainNamespace; | protected $domainNamespace; | ||||
/** | /** | ||||
* The number of tries for this Job. | |||||
* | |||||
* @var int | |||||
*/ | |||||
public $tries = 5; | |||||
/** | |||||
* Create a new job instance. | * Create a new job instance. | ||||
* | * | ||||
* @param int $domainId The ID for the user to create. | * @param int $domainId The ID for the user to create. | ||||
* | * | ||||
* @return void | * @return void | ||||
*/ | */ | ||||
public function __construct(int $domainId) | public function __construct(int $domainId) | ||||
{ | { | ||||
$this->domainId = $domainId; | $this->domainId = $domainId; | ||||
$domain = $this->getDomain(); | $domain = $this->getDomain(); | ||||
if ($domain) { | if ($domain) { | ||||
$this->domainNamespace = $domain->namespace; | $this->domainNamespace = $domain->namespace; | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Execute the job. | |||||
* | |||||
* @return void | |||||
*/ | |||||
abstract public function handle(); | |||||
/** | |||||
* Get the \App\Domain entry associated with this job. | * Get the \App\Domain entry associated with this job. | ||||
* | * | ||||
* @return \App\Domain|null | * @return \App\Domain|null | ||||
* | * | ||||
* @throws \Exception | * @throws \Exception | ||||
*/ | */ | ||||
protected function getDomain() | protected function getDomain() | ||||
{ | { | ||||
Show All 9 Lines |