|
1
|
|
|
<?php |
|
2
|
|
|
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
16
|
|
|
{ |
|
17
|
|
|
use Dispatchable, Queueable, InteractsWithQueue; |
|
18
|
|
|
|
|
19
|
|
|
private string $apiKey; |
|
|
|
|
|
|
20
|
|
|
private string $baseId; |
|
|
|
|
|
|
21
|
|
|
private string $tableName; |
|
|
|
|
|
|
22
|
|
|
private array $ids; |
|
|
|
|
|
|
23
|
|
|
private bool $debug = false; |
|
|
|
|
|
|
24
|
|
|
|
|
25
|
2 |
|
public function __construct(array $ids |
|
|
|
|
|
|
26
|
|
|
, string $apiKey, string $baseId, string $tableName) |
|
|
|
|
|
|
27
|
|
|
{ |
|
|
|
|
|
|
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() |
|
|
|
|
|
|
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) |
|
|
|
|
|
|
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) |
|
|
|
|
|
|
56
|
|
|
{ |
|
57
|
1 |
|
$this->debug = $debug; |
|
58
|
1 |
|
return $this; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function retryUntil() : \DateTime |
|
|
|
|
|
|
62
|
|
|
{ |
|
63
|
|
|
return now()->addHours(5); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
1 |
|
private function log(string $string) |
|
|
|
|
|
|
67
|
|
|
{ |
|
68
|
1 |
|
if($this->debug) { |
|
|
|
|
|
|
69
|
|
|
Log::debug($string); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
} |