Add rate limiting
This commit is contained in:
parent
e924be87df
commit
ba403c5f59
|
@ -7,6 +7,7 @@ use Illuminate\Contracts\Queue\ShouldQueue;
|
|||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\Redis;
|
||||
|
||||
class FillCoordsJob implements ShouldQueue
|
||||
{
|
||||
|
@ -31,20 +32,21 @@ class FillCoordsJob implements ShouldQueue
|
|||
*/
|
||||
public function handle()
|
||||
{
|
||||
Redis::throttle('osm')->block(0)->allow(1)->every(2)->then(function () {
|
||||
$address = $this->model->getAddressForGeolocation();
|
||||
|
||||
if (!$address) {
|
||||
$this->model->destroyCoordinate();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$coordinate = $address->getCoordinate();
|
||||
|
||||
if (!$coordinate) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->model->fillCoordinate($coordinate);
|
||||
}, function () {
|
||||
$this->release(5);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue