@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | $pdo->exec("CREATE TABLE IF NOT EXISTS `{$tableName}` (`service_key` VARCHAR(255) NOT NULL DEFAULT '', `service_last_try` DATETIME NULL DEFAULT '2000-01-01 00:00:00', `service_last_run` DATETIME NULL DEFAULT '2000-01-01 00:00:00', `service_timeout` INT UNSIGNED NULL DEFAULT '0', PRIMARY KEY (`service_key`));"); |
| 38 | 38 | |
| 39 | 39 | $skipLocked = ''; |
| 40 | - if($options['skip-locked'] ?? false) { |
|
| 40 | + if ($options['skip-locked'] ?? false) { |
|
| 41 | 41 | $skipLocked = ' SKIP LOCKED'; |
| 42 | 42 | } |
| 43 | 43 | $this->selectServices = $pdo->prepare("SELECT service_key FROM `{$tableName}` WHERE DATE_ADD(service_last_run, INTERVAL service_timeout SECOND) <= NOW() ORDER BY GREATEST(service_last_try, service_last_run) ASC FOR UPDATE{$skipLocked};"); |
@@ -68,13 +68,13 @@ discard block |
||
| 68 | 68 | */ |
| 69 | 69 | public function store($key, $timeout, array $data = []) { |
| 70 | 70 | $key = trim(strtolower($key)); |
| 71 | - if(!in_array($key, $this->services)) { |
|
| 71 | + if (!in_array($key, $this->services)) { |
|
| 72 | 72 | $this->services[] = $key; |
| 73 | 73 | } else { |
| 74 | 74 | throw new RuntimeException("Duplicate service: {$key}"); |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - if($this->has($key)) { |
|
| 77 | + if ($this->has($key)) { |
|
| 78 | 78 | $this->updateService->execute(['key' => $key, 'timeout' => $timeout]); |
| 79 | 79 | } else { |
| 80 | 80 | $this->insertService->execute(['key' => $key, 'timeout' => $timeout, 'try' => '2000-01-01 00:00:00', 'run' => '2000-01-01 00:00:00']); |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | $this->pdo->exec('START TRANSACTION'); |
| 94 | 94 | try { |
| 95 | 95 | $services = $this->fetchServices(); |
| 96 | - foreach($services as $service) { |
|
| 96 | + foreach ($services as $service) { |
|
| 97 | 97 | $this->updateTryDate->execute(['key' => $service['service_key']]); |
| 98 | 98 | $fn($service); |
| 99 | 99 | $this->updateRunDate->execute(['key' => $service['service_key']]); |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | } |
| 102 | 102 | $this->pdo->exec('COMMIT'); |
| 103 | 103 | return $count; |
| 104 | - } catch(Throwable $e) { |
|
| 104 | + } catch (Throwable $e) { |
|
| 105 | 105 | $this->pdo->exec('ROLLBACK'); |
| 106 | 106 | throw $e; |
| 107 | 107 | } |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | $this->selectServices->execute(); |
| 115 | 115 | try { |
| 116 | 116 | $services = $this->selectServices->fetchAll(PDO::FETCH_ASSOC); |
| 117 | - foreach($services as $service) { |
|
| 117 | + foreach ($services as $service) { |
|
| 118 | 118 | yield new Service($service['service_key']); |
| 119 | 119 | } |
| 120 | 120 | } finally { |