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