bristol-su /
airtable
| 1 | <?php |
||
| 2 | |||
|
0 ignored issues
–
show
Coding Style
introduced
by
Loading history...
|
|||
| 3 | |||
| 4 | namespace BristolSU\AirTable\Jobs; |
||
| 5 | |||
| 6 | |||
| 7 | use BristolSU\AirTable\AirTable; |
||
| 8 | use Illuminate\Bus\Queueable; |
||
| 9 | use Illuminate\Contracts\Queue\ShouldQueue; |
||
| 10 | use Illuminate\Foundation\Bus\Dispatchable; |
||
| 11 | use Illuminate\Queue\InteractsWithQueue; |
||
| 12 | use Illuminate\Support\Facades\Log; |
||
| 13 | use Spatie\RateLimitedMiddleware\RateLimited; |
||
| 14 | |||
| 15 | class DeleteRows implements ShouldQueue |
||
|
0 ignored issues
–
show
|
|||
| 16 | { |
||
| 17 | use Dispatchable, Queueable, InteractsWithQueue; |
||
| 18 | |||
| 19 | private string $apiKey; |
||
|
0 ignored issues
–
show
|
|||
| 20 | private string $baseId; |
||
|
0 ignored issues
–
show
|
|||
| 21 | private string $tableName; |
||
|
0 ignored issues
–
show
|
|||
| 22 | private array $ids; |
||
|
0 ignored issues
–
show
|
|||
| 23 | private bool $debug = false; |
||
|
0 ignored issues
–
show
|
|||
| 24 | |||
| 25 | 2 | public function __construct(array $ids |
|
|
0 ignored issues
–
show
|
|||
| 26 | , string $apiKey, string $baseId, string $tableName) |
||
|
0 ignored issues
–
show
|
|||
| 27 | { |
||
|
0 ignored issues
–
show
|
|||
| 28 | 2 | $this->apiKey = $apiKey; |
|
| 29 | 2 | $this->baseId = $baseId; |
|
| 30 | 2 | $this->tableName = $tableName; |
|
| 31 | 2 | $this->ids = $ids; |
|
| 32 | 2 | } |
|
| 33 | |||
| 34 | public function middleware() |
||
|
0 ignored issues
–
show
|
|||
| 35 | { |
||
| 36 | $rateLimitedMiddleware = (new RateLimited()) |
||
| 37 | ->key('airtable') |
||
| 38 | ->allow(1) |
||
| 39 | ->everySeconds(1) |
||
| 40 | ->releaseAfterSeconds(3); |
||
| 41 | |||
| 42 | return [$rateLimitedMiddleware]; |
||
| 43 | } |
||
| 44 | |||
| 45 | 1 | public function handle(AirTable $airTable) |
|
|
0 ignored issues
–
show
|
|||
| 46 | { |
||
| 47 | 1 | $airTable->setApiKey($this->apiKey); |
|
| 48 | 1 | $airTable->setBaseId($this->baseId); |
|
| 49 | 1 | $airTable->setTableName($this->tableName); |
|
| 50 | 1 | $this->log('Deleting Rows'); |
|
| 51 | 1 | $airTable->deleteRows($this->ids); |
|
| 52 | 1 | $this->log('Deleted Rows'); |
|
| 53 | 1 | } |
|
| 54 | |||
| 55 | 1 | public function withDebug(bool $debug) |
|
|
0 ignored issues
–
show
|
|||
| 56 | { |
||
| 57 | 1 | $this->debug = $debug; |
|
| 58 | 1 | return $this; |
|
| 59 | } |
||
| 60 | |||
| 61 | public function retryUntil() : \DateTime |
||
|
0 ignored issues
–
show
|
|||
| 62 | { |
||
| 63 | return now()->addHours(5); |
||
| 64 | } |
||
| 65 | |||
| 66 | 1 | private function log(string $string) |
|
|
0 ignored issues
–
show
|
|||
| 67 | { |
||
| 68 | 1 | if($this->debug) { |
|
|
0 ignored issues
–
show
|
|||
| 69 | Log::debug($string); |
||
| 70 | } |
||
| 71 | } |
||
| 72 | } |