Skip to content

Commit

Permalink
FIX Remove stalled job if implementation not found (#350)
Browse files Browse the repository at this point in the history
* Remove stalled job if implementation not found

If a job class is renamed or removed, remove the related stalled jobs rather than throwing an exception (which prevents the rest of the jobs from running).

* Handle case if jobDescriptor is deleted.

When `refreshDescriptor()` updates $this->descriptor from the database, potentially this object can be null. This change checks to ensure `$this->descriptor` is set before calling any methods.
  • Loading branch information
wilr authored Aug 5, 2021
1 parent 2339ecd commit 6f936a7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
37 changes: 23 additions & 14 deletions src/Jobs/DoormanQueuedJobTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class DoormanQueuedJobTask implements Task, Expires, Process, Cancellable
protected $id;

/**
* @var QueuedJobDescriptor
* @var QueuedJobDescriptor|null
*/
protected $descriptor;

Expand Down Expand Up @@ -132,7 +132,7 @@ public function getData()
*/
public function ignoresRules()
{
if ($this->descriptor->hasMethod('ignoreRules')) {
if ($this->descriptor && $this->descriptor->hasMethod('ignoreRules')) {
return $this->descriptor->ignoreRules();
}

Expand All @@ -144,7 +144,7 @@ public function ignoresRules()
*/
public function stopsSiblings()
{
if ($this->descriptor->hasMethod('stopsSiblings')) {
if ($this->descriptor && $this->descriptor->hasMethod('stopsSiblings')) {
return $this->descriptor->stopsSiblings();
}

Expand All @@ -158,7 +158,7 @@ public function stopsSiblings()
*/
public function getExpiresIn()
{
if ($this->descriptor->hasMethod('getExpiresIn')) {
if ($this->descriptor && $this->descriptor->hasMethod('getExpiresIn')) {
return $this->descriptor->getExpiresIn();
}

Expand All @@ -173,7 +173,7 @@ public function getExpiresIn()
*/
public function shouldExpire($startedAt)
{
if ($this->descriptor->hasMethod('shouldExpire')) {
if ($this->descriptor && $this->descriptor->hasMethod('shouldExpire')) {
return $this->descriptor->shouldExpire($startedAt);
}

Expand All @@ -188,14 +188,19 @@ public function shouldExpire($startedAt)
public function canRunTask()
{
$this->refreshDescriptor();
return in_array(
$this->descriptor->JobStatus,
array(
QueuedJob::STATUS_NEW,
QueuedJob::STATUS_INIT,
QueuedJob::STATUS_WAIT
)
);

if ($this->descriptor) {
return in_array(
$this->descriptor->JobStatus,
array(
QueuedJob::STATUS_NEW,
QueuedJob::STATUS_INIT,
QueuedJob::STATUS_WAIT
)
);
}

return false;
}

/**
Expand All @@ -213,6 +218,10 @@ public function isCancelled()
QueuedJob::STATUS_COMPLETE,
];

return in_array($this->descriptor->JobStatus, $cancelledStates, true);
if ($this->descriptor) {
return in_array($this->descriptor->JobStatus, $cancelledStates, true);
}

return true;
}
}
7 changes: 7 additions & 0 deletions src/Services/QueuedJobService.php
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,13 @@ public function checkJobHealth($queue = null)
/** @var QueuedJobDescriptor $stalledJob */
foreach ($stalledJobs as $stalledJob) {
$jobClass = $stalledJob->Implementation;

if (!class_exists($jobClass)) {
$stalledJob->delete();

continue;
}

$jobSingleton = singleton($jobClass);

if ($jobSingleton instanceof RunBuildTaskJob) {
Expand Down

0 comments on commit 6f936a7

Please sign in to comment.