Skip to content

Commit

Permalink
Add exception context on failed jobs (#1115)
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinelame committed Feb 5, 2022
1 parent 89dd54d commit de11b32
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
10 changes: 10 additions & 0 deletions resources/js/screens/failedJobs/job.vue
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,16 @@
</div>
</div>

<div class="card mt-4" v-if="ready">
<div class="card-header d-flex align-items-center justify-content-between">
<h5>Exception Context</h5>
</div>

<div class="card-body code-bg text-white">
<vue-json-pretty :data="prettyPrintJob(job.context)"></vue-json-pretty>
</div>
</div>


<div class="card mt-4" v-if="ready">
<div class="card-header d-flex align-items-center justify-content-between">
Expand Down
2 changes: 2 additions & 0 deletions src/Http/Controllers/FailedJobsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ protected function decode($job)

$job->exception = mb_convert_encoding($job->exception, 'UTF-8');

$job->context = json_decode($job->context);

$job->retried_by = collect(json_decode($job->retried_by))
->sortByDesc('retried_at')->values();

Expand Down
8 changes: 6 additions & 2 deletions src/Repositories/RedisJobRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ class RedisJobRepository implements JobRepository
*/
public $keys = [
'id', 'connection', 'queue', 'name', 'status', 'payload',
'exception', 'failed_at', 'completed_at', 'retried_by', 'reserved_at',
'exception', 'context', 'failed_at', 'completed_at', 'retried_by',
'reserved_at',
];

/**
Expand Down Expand Up @@ -597,7 +598,7 @@ public function findFailed($id)
/**
* Mark the job as failed.
*
* @param string $exception
* @param \Exception $exception
* @param string $connection
* @param string $queue
* @param \Laravel\Horizon\JobPayload $payload
Expand All @@ -620,6 +621,9 @@ public function failed($exception, $connection, $queue, JobPayload $payload)
'status' => 'failed',
'payload' => $payload->value,
'exception' => (string) $exception,
'context' => method_exists($exception, 'context')
? json_encode($exception->context())
: null,
'failed_at' => str_replace(',', '.', microtime(true)),
]
);
Expand Down

0 comments on commit de11b32

Please sign in to comment.