diff --git a/src/FillCoordsJob.php b/src/FillCoordsJob.php index 826f491..9083ddc 100644 --- a/src/FillCoordsJob.php +++ b/src/FillCoordsJob.php @@ -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() { - $address = $this->model->getAddressForGeolocation(); + Redis::throttle('osm')->block(0)->allow(1)->every(2)->then(function () { + $address = $this->model->getAddressForGeolocation(); + if (!$address) { + $this->model->destroyCoordinate(); - if (!$address) { - $this->model->destroyCoordinate(); + return; + } + $coordinate = $address->getCoordinate(); - return; - } - - $coordinate = $address->getCoordinate(); - - if (!$coordinate) { - return; - } - - $this->model->fillCoordinate($coordinate); + if (!$coordinate) { + return; + } + $this->model->fillCoordinate($coordinate); + }, function () { + $this->release(5); + }); } }