| | |
| | | |
| | | $ops = $this->storage->fetchRunnable(3); |
| | | |
| | | $lastOpId = null; |
| | | foreach ($ops as $op) { |
| | | if (!$this->dependenciesSatisfied($op)) { |
| | | continue; |
| | | } |
| | | if (!$this->storage->markProcessing($op->id)) { |
| | | continue; |
| | | } |
| | | $lastOpId = $op->id; |
| | | $this->processOne($op); |
| | | usleep(10000); |
| | | } |
| | |
| | | |
| | | return true; |
| | | } |
| | | |
| | | private function dependenciesSatisfied(Operation $op): bool |
| | | { |
| | | if (empty($op->dependencies)) { |
| | | return true; |
| | | } |
| | | |
| | | foreach ($op->dependencies as $depId) { |
| | | $dep = $this->storage->find($depId); |
| | | |
| | | // Missing dependency = block (or decide to ignore; your call) |
| | | if (!$dep) { |
| | | return false; |
| | | } |
| | | |
| | | if ($dep->state !== 'completed') { |
| | | return false; |
| | | } |
| | | |
| | | if (!in_array($dep->outcome, ['success', 'partial'], true)) { |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | |
| | | } |