dev-think-one /
laravel-myriad-data-store
| 1 | <?php |
||
| 2 | |||
| 3 | namespace MyriadDataStore\Jobs; |
||
| 4 | |||
| 5 | use Illuminate\Bus\Queueable; |
||
| 6 | use Illuminate\Contracts\Queue\ShouldQueue; |
||
| 7 | use Illuminate\Foundation\Bus\Dispatchable; |
||
| 8 | use Illuminate\Queue\InteractsWithQueue; |
||
| 9 | use Illuminate\Queue\SerializesModels; |
||
| 10 | use Illuminate\Support\Facades\Log; |
||
| 11 | use MyriadSoap\MyriadSoapException; |
||
| 12 | |||
| 13 | class DownloadMyriadContacts implements ShouldQueue |
||
| 14 | { |
||
| 15 | use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 16 | |||
| 17 | public static bool|string $logErrors = false; |
||
| 18 | |||
| 19 | protected int $startContactId = 1; |
||
| 20 | protected int $count = 1000; |
||
| 21 | |||
| 22 | 4 | public function __construct($startContactId = 1, $count = 1000) |
|
| 23 | { |
||
| 24 | 4 | if ($startContactId <= 0) { |
|
| 25 | 1 | throw new \Exception("Invalid start value [$startContactId]"); |
|
| 26 | } |
||
| 27 | 3 | if ($count <= 0 || $count > 100000) { |
|
| 28 | 1 | throw new \Exception("Invalid count value [$count]"); |
|
| 29 | } |
||
| 30 | |||
| 31 | 2 | $this->startContactId = $startContactId; |
|
| 32 | 2 | $this->count = $count; |
|
| 33 | } |
||
| 34 | |||
| 35 | 1 | public function handle(\MyriadDataStore\Actions\DownloadMyriadContact $action) |
|
| 36 | { |
||
| 37 | 1 | for ($i = $this->startContactId; $i < ($this->startContactId + $this->count); $i++) { |
|
| 38 | try { |
||
| 39 | 1 | $action->execute($i); |
|
| 40 | 1 | } catch (MyriadSoapException $e) { |
|
| 41 | 1 | if (static::$logErrors) { |
|
| 42 | 1 | Log::log( |
|
| 43 | 1 | is_string(static::$logErrors) ? static::$logErrors : 'error', |
|
| 44 | 1 | "Contact [$i] error: ".$e->getMessage() |
|
| 45 | 1 | ); |
|
| 46 | } |
||
| 47 | } |
||
| 48 | } |
||
| 49 | } |
||
| 50 | } |
||
| 51 |