Page MenuHomePhorge

GroupJob.php
No OneTemporary

Size
1 KB
Referenced Files
None
Subscribers
None

GroupJob.php

<?php
namespace App\Jobs;
/**
* The abstract \App\Jobs\GroupJob implements the logic needed for all dispatchable Jobs related to
* \App\Group objects.
*
* ```php
* $job = new \App\Jobs\Group\CreateJob($groupId);
* $job->handle();
* ```
*/
abstract class GroupJob extends CommonJob
{
/**
* The ID for the \App\Group. This is the shortest globally unique identifier and saves Redis space
* compared to a serialized version of the complete \App\Group object.
*
* @var int
*/
protected $groupId;
/**
* The \App\Group email property, for legibility in the queue management.
*
* @var string
*/
protected $groupEmail;
/**
* Create a new job instance.
*
* @param int $groupId The ID for the group to create.
*
* @return void
*/
public function __construct(int $groupId)
{
$this->groupId = $groupId;
$group = $this->getGroup();
if ($group) {
$this->groupEmail = $group->email;
}
}
/**
* Get the \App\Group entry associated with this job.
*
* @return \App\Group|null
*
* @throws \Exception
*/
protected function getGroup()
{
$group = \App\Group::withTrashed()->find($this->groupId);
if (!$group) {
// The record might not exist yet in case of a db replication environment
// This will release the job and delay another attempt for 5 seconds
if ($this instanceof Group\CreateJob) {
$this->release(5);
return null;
}
$this->fail(new \Exception("Group {$this->groupId} could not be found in the database."));
}
return $group;
}
}

File Metadata

Mime Type
text/x-php
Expires
Fri, Nov 21, 5:16 AM (1 d, 12 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
387374
Default Alt Text
GroupJob.php (1 KB)

Event Timeline