Any failed jobs will end up in the failed_jobs table, so it usually makes more sense to review them and/or schedule them to try again after a certain period of time (for example, if you know the API you're dealing with is flaky sometimes).
Oct 1, 2023
5
Level 1
In Laravel How to get the ID of a Queue Job?
So I have this code, what I am trying to do is able to get the UUID, so that I can retry it later if it fails.
$sendMailJob = (new SendQueueEmail($mailSent, $filePaths));
$uuid = $sendMailJob->uuid;
// dispatch job
dispatch($sendMailJob);
but of course, this does not work, how can I get the UUID?
Level 1
I was able to get the job uuid inside my Queue Job Class under handle function :
public function handle()
{
try {
$uuid = $this->job->uuid(); //
// some codes here
I need to save it so that I can retry it later if it fails or an API throws an error. What I like about this is that the failed Job also saves the error message I can use for debugging and stuffing.
with this I can just create a function like this:
public function retryFailedSent($uuid): JsonResponse
{
try {
$failedJob = DB::table('failed_jobs')->where('uuid', $uuid)->first();
if (!$failedJob) throw new Exception("Failed Job Not Found!");
Artisan::call('queue:retry '.$uuid);
return response()->json(['message' => "Email is being sent."]);
} catch (Exception $e) {
return response()->json(['message' => $e->getMessage()], 422);
}
}
Please or to participate in this conversation.