| Conditions | 4 |
| Paths | 8 |
| Total Lines | 24 |
| Code Lines | 14 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 31 | public function handle(): int |
||
| 32 | { |
||
| 33 | $start = now(); |
||
| 34 | |||
| 35 | $this->info('Waiting for the DB connection to become available.'); |
||
| 36 | |||
| 37 | foreach (range(1, $this->option('max-attempts')) as $attempt) { |
||
| 38 | try { |
||
| 39 | DB::connection()->getPdo(); |
||
| 40 | $time = abs(now()->diffInSeconds($start)); |
||
| 41 | $this->info("Took {$time} seconds to connect to the DB."); |
||
| 42 | |||
| 43 | return self::SUCCESS; |
||
| 44 | } catch (Exception $exception) { |
||
| 45 | if ($attempt == $this->option('max-attempts')) { |
||
| 46 | throw $exception; |
||
| 47 | } |
||
| 48 | |||
| 49 | $this->info("Connect to DB attempt #{$attempt} failed, trying again in {$this->option('interval')} seconds"); |
||
| 50 | sleep($this->option('interval')); |
||
| 51 | } |
||
| 52 | } |
||
| 53 | |||
| 54 | return self::FAILURE; |
||
| 55 | } |
||
| 57 |