Try to prevent overlaping on job setServiceStat

This commit is contained in:
Jérémy Munsch 2021-10-15 18:36:02 +02:00
parent 94aeac4892
commit c70d8bd376
No known key found for this signature in database
GPG key ID: 55196BEE445F6049

View file

@ -8,6 +8,7 @@ use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\Middleware\WithoutOverlapping;
use Illuminate\Queue\SerializesModels;
class SetServiceStats implements ShouldQueue
@ -17,6 +18,9 @@ class SetServiceStats implements ShouldQueue
use Queueable;
use SerializesModels;
/** Used to prevent overlaping */
private const JOBKEY = 95563222;
/** @var \App\Models\Service */
protected $service;
@ -45,4 +49,9 @@ class SetServiceStats implements ShouldQueue
$serviceStat->nb_calls += 1;
$serviceStat->saveOrFail();
}
public function middleware()
{
return [(new WithoutOverlapping(self::JOBKEY))->releaseAfter(30)];
}
}