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