You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In my jobs_batch table, some batch jobs have the "pending_jobs" field at -1 instead of 0 after all jobs have been dispatch. When the field is negative I noticed that it is duplicating the same job
public function __construct(protected array $jobs)
{
}
public function dispatchBus()
{
$batch = Bus::batch($this->jobs)->finally(function (Batch $batch) {
$invoice = new InvoiceService($batch->id);
$invoice->send(); //send laravel notification
})
->allowFailures()
->onQueue('invoice')
->dispatch();
return $batch;
}
my individual job from the array of jobs that is sent to the batch
class InvoiceJob implements ShouldQueue, ShouldBeUnique
{
use Batchable, Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public function __construct(protected Plan $plan, protected companyModel $company, protected bool $sandbox = false)
{
}
public $uniqueFor = 3600;
public $tries = 3;
public function uniqueId(): string
{
return $this->plan->id;
}
public function handle(): void
{
if ($this->batch()->cancelled()) {
return;
}
try {
$invoiceService = new InvoiceService($this->company, sandbox: $this->sandbox, batch_id: $this->batch()->id);
$invoice = $invoiceService->apiExec($this->plan);
if ($this->plan->client->type === 'pj') {
$invoiceService->sendEmail($invoice);
}
} catch (Throwable $exception) {
Batch::addLog($this->batch()->id, "Fail: {$this->plan->client->code} - {$this->plan->client->name}
Erro: {$exception->getMessage()}");
$this->fail();
}
}
}
What causes this to have this batch behavior with a negative value?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
In my jobs_batch table, some batch jobs have the "pending_jobs" field at -1 instead of 0 after all jobs have been dispatch. When the field is negative I noticed that it is duplicating the same job
my individual job from the array of jobs that is sent to the batch
What causes this to have this batch behavior with a negative value?
Beta Was this translation helpful? Give feedback.
All reactions