Add rate limiting

This commit is contained in:
philipp lang 2024-07-09 12:13:37 +02:00
parent e924be87df
commit ba403c5f59
1 changed files with 15 additions and 13 deletions

View File

@ -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);
});
}
}