runs = $runs; $this->tasks = $tasks; } /** * @param list $check_ids Planned registry check IDs. */ public function create( string $profile, string $language, string $registry_version, Budget $budget, array $check_ids, int $actor_id = 0 ): RunRecord { if ( array() === $check_ids || count( $check_ids ) !== count( array_unique( $check_ids ) ) ) { throw new InvalidArgumentException( 'invalid_check_plan' ); } $run = $this->runs->create( $profile, $language, $registry_version, $budget, $actor_id ); $run = $this->runs->transition( $run->uuid(), RunStatus::PREFLIGHT, $actor_id ); try { foreach ( $check_ids as $check_id ) { $this->tasks->enqueue( $run->id(), $check_id ); } } catch ( StorageException $exception ) { $this->runs->transition( $run->uuid(), RunStatus::FAILED ); throw $exception; } $this->runs->update_coverage( $run->id(), 0, count( $check_ids ) ); return $this->runs->transition( $run->uuid(), RunStatus::QUEUED, $actor_id ); } public function start( string $uuid, int $actor_id = 0 ): RunRecord { return $this->runs->transition( $uuid, RunStatus::RUNNING, $actor_id ); } public function pause( string $uuid, int $actor_id = 0 ): RunRecord { return $this->runs->transition( $uuid, RunStatus::PAUSED, $actor_id ); } public function resume( string $uuid, int $actor_id = 0 ): RunRecord { return $this->runs->transition( $uuid, RunStatus::QUEUED, $actor_id ); } public function cancel( string $uuid, int $actor_id = 0 ): RunRecord { $run = $this->runs->transition( $uuid, RunStatus::CANCELLED, $actor_id ); $this->tasks->cancel_open( $run->id() ); return $run; } public function settle( string $uuid ): RunRecord { $run = $this->require_run( $uuid ); $counts = $this->tasks->counts( $run->id() ); $this->runs->update_coverage( $run->id(), $counts['completed'], $counts['total'] ); if ( $counts['failed'] > 0 ) { return $this->runs->transition( $uuid, RunStatus::FAILED ); } if ( $counts['total'] > 0 && $counts['completed'] === $counts['total'] ) { return $this->runs->transition( $uuid, RunStatus::COMPLETED ); } return $run; } private function require_run( string $uuid ): RunRecord { $run = $this->runs->get_by_uuid( $uuid ); if ( null === $run ) { throw new StorageException( 'run_not_found' ); } return $run; } }