Answer the question
In order to leave comments, you need to log in
Why are some queue jobs in Laravel repeated twice?
I am using job chaining and sometimes I find that the jobs are running again. Here is an example of my code:
<?php
namespace App\Http\Controllers;
use App\Jobs\SendInvoice;
use Illuminate\Http\Request;
use JustIversen\JobChainer\JobChainer;
class NotificationsController extends Controller
{
public function bulk_sending_by_type(Request $request)
{
$numbers = $request->numbers;
$chain = new JobChainer;
foreach ($numbers as $key => $number){
$chain->add(SendInvoice::class, $number);
}
$chain->dispatch();
return response()->json([]);
}
}
<?php
namespace App\Jobs;
use App\Helper\InvoicesHelper;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class SendInvoice implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public $tries = 1;
protected $number;
public $queue;
public $timeout = 500;
public function __construct($number )
{
$this->queue = 'invoices';
$this->number = $number;
}
public function handle()
{
InvoicesHelper::send_invoice($this->number);
sleep(30);
}
}
'connections' => [
'sync' => [
'driver' => 'sync',
],
'invoices' => [
'driver' => 'database',
'table' => 'jobs',
'queue' => 'invoices',
'retry_after' => 520,
],
],
[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/sites/test.fo/public/artisan queue:work --queue=invoices --tries=1
autostart=true
autorestart=true
user=main
numprocs=1
redirect_stderr=true
stdout_logfile=/var/www/sites/test.fo/public/worker.log
stopwaitsecs=9000
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question