Skip to content

Commit

Permalink
FIX releaseJobLock when marking a job as broken (#354)
Browse files Browse the repository at this point in the history
FIX releaseJobLock when marking a job as broken
  • Loading branch information
andrewandante authored and Maxime Rainville committed Oct 19, 2021
1 parent 89f00a3 commit a5862ce
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
22 changes: 11 additions & 11 deletions src/Services/QueuedJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,32 @@ interface QueuedJob
* Always run immediate jobs as soon as possible
* @var string
*/
const IMMEDIATE = '1';
public const IMMEDIATE = '1';

/**
* Queued jobs may have some processing to do, but should be pretty quick
* @var string
*/
const QUEUED = '2';
public const QUEUED = '2';

/**
* Large jobs will take minutes, not seconds to run
* @var string
*/
const LARGE = '3';
public const LARGE = '3';

/**
* Statuses
* @var string
*/
const STATUS_NEW = 'New';
const STATUS_INIT = 'Initialising';
const STATUS_RUN = 'Running';
const STATUS_WAIT = 'Waiting';
const STATUS_COMPLETE = 'Complete';
const STATUS_PAUSED = 'Paused';
const STATUS_CANCELLED = 'Cancelled';
const STATUS_BROKEN = 'Broken';
public const STATUS_NEW = 'New';
public const STATUS_INIT = 'Initialising';
public const STATUS_RUN = 'Running';
public const STATUS_WAIT = 'Waiting';
public const STATUS_COMPLETE = 'Complete';
public const STATUS_PAUSED = 'Paused';
public const STATUS_CANCELLED = 'Cancelled';
public const STATUS_BROKEN = 'Broken';

/**
* Gets a title for the job that can be used in listings
Expand Down
17 changes: 14 additions & 3 deletions src/Services/QueuedJobService.php
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,7 @@ public function runJob($jobId)
$job->process();
} catch (\Throwable $e) {
$logger->error($e->getMessage(), ['exception' => $e]);
$jobDescriptor->JobStatus = QueuedJob::STATUS_BROKEN;
$this->markJobAsBroken($jobDescriptor);
$this->extend('updateJobDescriptorAndJobOnException', $jobDescriptor, $job, $e);
}

Expand All @@ -930,7 +930,7 @@ public function runJob($jobId)
'Job stalled after {attempts} attempts - please check',
['attempts' => $stallCount]
));
$jobDescriptor->JobStatus = QueuedJob::STATUS_BROKEN;
$this->markJobAsBroken($jobDescriptor);
}

// now we'll be good and check our memory usage. If it is too high, we'll set the job to
Expand Down Expand Up @@ -1056,7 +1056,7 @@ protected function handleBrokenJobException(QueuedJobDescriptor $jobDescriptor,
'exception' => $e,
]
);
$jobDescriptor->JobStatus = QueuedJob::STATUS_BROKEN;
$this->markJobAsBroken($jobDescriptor);
$this->extend('updateJobDescriptorAndJobOnException', $jobDescriptor, $job, $e);
$jobDescriptor->write();
}
Expand Down Expand Up @@ -1516,6 +1516,17 @@ protected function releaseJobLock(QueuedJobDescriptor $descriptor): void
$descriptor->Worker = null;
}

/**
* Mark a Job as Broken and release the lock so it can be resumed
*
* @param QueuedJobDescriptor $descriptor
*/
protected function markJobAsBroken(QueuedJobDescriptor $descriptor): void
{
$descriptor->JobStatus = QueuedJob::STATUS_BROKEN;
$this->releaseJobLock($descriptor);
}

/**
* @return string
*/
Expand Down

0 comments on commit a5862ce

Please sign in to comment.