How to disable import action job retries?

I'm relatively new to handling jobs and queues in Laravel. Despite my efforts, the jobs related to the import action repeatedly fail and continue retrying. I attempted to limit retries by using --tries=1 on the worker, but this didn't change the outcome. Additionally, I modified the default job class as follows:
<?php

namespace App\Jobs;

use Carbon\CarbonInterface;
use Filament\Actions\Imports\Jobs\ImportCsv;

class ImportTasksJob extends ImportCsv
{
public function getJobRetryUntil(): ?CarbonInterface
{
return now()->addSecond(1);
}
}
<?php

namespace App\Jobs;

use Carbon\CarbonInterface;
use Filament\Actions\Imports\Jobs\ImportCsv;

class ImportTasksJob extends ImportCsv
{
public function getJobRetryUntil(): ?CarbonInterface
{
return now()->addSecond(1);
}
}
Added ->job(ImportTasksJob::class). However, this modification also had no impact. In the beforeFill method:
protected function beforeFill(): void
{
try {
// do something
} catch (\Exception $e) {
// The job keeps retrying endlessly when an error occur
throw $e;
}
}
protected function beforeFill(): void
{
try {
// do something
} catch (\Exception $e) {
// The job keeps retrying endlessly when an error occur
throw $e;
}
}
The issue persists where the job endlessly retries in the event of an error.
1 Reply
spinther
spinther4mo ago
This is what I ended up doing but I'm not sure if this is the best approach:
class ImportTasksJob extends ImportCsv
{

public function handle(): void
{
$user = $this->import->user;
try {
parent::handle();
} catch (ValidationException $exception) {
// Handle validation exceptions (logging, etc.)
Notification::make()
->title('Import Failed')
->body("The import job failed due to an error: {$exception->getMessage()}")
->danger()
->sendToDatabase($user);

$this->fail($exception);
} catch (Throwable $exception) {
// Handle general exceptions
Notification::make()
->title('Import Failed')
->body("The import job failed due to an error: {$exception->getMessage()}")
->danger()
->sendToDatabase($user);

$this->fail($exception);
}
}
}
class ImportTasksJob extends ImportCsv
{

public function handle(): void
{
$user = $this->import->user;
try {
parent::handle();
} catch (ValidationException $exception) {
// Handle validation exceptions (logging, etc.)
Notification::make()
->title('Import Failed')
->body("The import job failed due to an error: {$exception->getMessage()}")
->danger()
->sendToDatabase($user);

$this->fail($exception);
} catch (Throwable $exception) {
// Handle general exceptions
Notification::make()
->title('Import Failed')
->body("The import job failed due to an error: {$exception->getMessage()}")
->danger()
->sendToDatabase($user);

$this->fail($exception);
}
}
}
Ultimately, there should be a way to update the error message in the "Download information about the failed row" CSV file.