@@ -65,13 +65,13 @@ discard block |
||
| 65 | 65 | */ |
| 66 | 66 | public function store($key, $timeout, array $data = []) { |
| 67 | 67 | $key = trim(strtolower($key)); |
| 68 | - if(!in_array($key, $this->services)) { |
|
| 68 | + if (!in_array($key, $this->services)) { |
|
| 69 | 69 | $this->services[] = $key; |
| 70 | 70 | } else { |
| 71 | 71 | throw new RuntimeException("Duplicate service: {$key}"); |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - if($this->has($key)) { |
|
| 74 | + if ($this->has($key)) { |
|
| 75 | 75 | $this->updateService->execute(['key' => $key, 'timeout' => $timeout]); |
| 76 | 76 | } else { |
| 77 | 77 | $this->insertService->execute(['key' => $key, 'timeout' => $timeout, 'try' => '2000-01-01 00:00:00', 'run' => '2000-01-01 00:00:00']); |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | public function lockAndIterateServices($fn) { |
| 89 | 89 | $count = 0; |
| 90 | 90 | $services = $this->fetchServices(); |
| 91 | - foreach($services as $service) { |
|
| 91 | + foreach ($services as $service) { |
|
| 92 | 92 | $this->updateTryDate->execute(['key' => $service->getKey()]); |
| 93 | 93 | $this->pdo->exec('BEGIN EXCLUSIVE TRANSACTION'); |
| 94 | 94 | try { |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | $this->updateRunDate->execute(['key' => $service->getKey()]); |
| 98 | 98 | $count++; |
| 99 | 99 | $this->pdo->exec('COMMIT'); |
| 100 | - } catch(Throwable $e) { |
|
| 100 | + } catch (Throwable $e) { |
|
| 101 | 101 | $this->pdo->exec('ROLLBACK'); |
| 102 | 102 | throw $e; |
| 103 | 103 | } |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | $this->selectServices->execute(); |
| 113 | 113 | try { |
| 114 | 114 | $services = $this->selectServices->fetchAll(PDO::FETCH_ASSOC); |
| 115 | - foreach($services as $service) { |
|
| 115 | + foreach ($services as $service) { |
|
| 116 | 116 | yield new Service($service['service_key']); |
| 117 | 117 | } |
| 118 | 118 | } finally { |
@@ -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']); |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | public function lockAndIterateServices($fn) { |
| 92 | 92 | $count = 0; |
| 93 | 93 | $services = $this->fetchServices(); |
| 94 | - foreach($services as $service) { |
|
| 94 | + foreach ($services as $service) { |
|
| 95 | 95 | $this->updateTryDate->execute(['key' => $service->getKey()]); |
| 96 | 96 | $this->pdo->exec('START TRANSACTION'); |
| 97 | 97 | try { |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | $this->updateRunDate->execute(['key' => $service->getKey()]); |
| 101 | 101 | $count++; |
| 102 | 102 | $this->pdo->exec('COMMIT'); |
| 103 | - } catch(Throwable $e) { |
|
| 103 | + } catch (Throwable $e) { |
|
| 104 | 104 | $this->pdo->exec('ROLLBACK'); |
| 105 | 105 | throw $e; |
| 106 | 106 | } |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | $this->selectServices->execute(); |
| 116 | 116 | try { |
| 117 | 117 | $services = $this->selectServices->fetchAll(PDO::FETCH_ASSOC); |
| 118 | - foreach($services as $service) { |
|
| 118 | + foreach ($services as $service) { |
|
| 119 | 119 | yield new Service($service['service_key']); |
| 120 | 120 | } |
| 121 | 121 | } finally { |