Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.x] Add exception context on failed jobs #1115

Merged
merged 1 commit into from
Feb 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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