Skip to content
Snippets Groups Projects
Verified Commit ff853b47 authored by Dillenn Terumalai's avatar Dillenn Terumalai :speech_balloon:
Browse files

fix: Added exception when job fails

parent ba0af493
No related branches found
No related tags found
No related merge requests found
Pipeline #3909 passed
......@@ -38,9 +38,10 @@ class {{ class }} implements ClusterShouldQueue, ClusterWithCallbacks
* Execute the following callback when the job fails
*
* @param \Dterumal\LaravelCluster\Storage\JobModel $job
* @param \Throwable $e
* @return void
*/
public function onFailure(JobModel $job): void
public function onFailure(JobModel $job, \Throwable $e): void
{
//
}
......
......@@ -8,7 +8,7 @@ use Dterumal\LaravelCluster\Storage\JobModel;
interface ClusterWithCallbacks
{
public function onFailure(JobModel $clusterJob): void;
public function onFailure(JobModel $clusterJob, \Throwable $e): void;
public function onSuccess(JobModel $clusterJob): void;
......
......@@ -6,6 +6,11 @@ use Dterumal\LaravelCluster\Events\JobFailed;
class ExecuteJobFailureCallback
{
/**
* @var string
*/
public string $exception = 'Job failed';
/**
* Handle the event.
*
......@@ -16,8 +21,16 @@ class ExecuteJobFailureCallback
{
$jobClass = $event->job->job;
try {
if (file_exists($this->job->std_err_path)) {
$this->exception = file_get_contents($this->job->std_err_path);
}
throw new \Exception($this->exception);
} catch (\Throwable $e) {
if (method_exists($jobClass, 'onFailure')) {
$jobClass->onFailure($event->job);
$jobClass->onFailure($event->job, $e);
}
}
}
}
......@@ -131,9 +131,10 @@ class MyFooClusterJob implements ClusterShouldQueue, ClusterWithCallbacks
* Execute the following callback when the job fails
*
* @param \Dterumal\LaravelCluster\Storage\JobModel \$job
* @param \Throwable \$e
* @return void
*/
public function onFailure(JobModel \$job): void
public function onFailure(JobModel \$job, \Throwable \$e): void
{
//
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment