getRepository()->fetchAll(); return $this->withJson($response, compact('jobs')); } public function schedule(ServerRequestInterface $request, ResponseInterface $response, Service $service): ResponseInterface { $body = $request->getBody(); $json = json_decode($body->getContents()); if (!isset($json->jobs)) { throw new MissingArgument('jobs', 'array', 'job commands with arguments'); } $output = [ 'jobs' => $json->jobs, 'total' => count($json->jobs), 'scheduled' => 0 ]; foreach ($json->jobs as $job) { if ($service->queue($job->command, $job->arguments)) { $output['scheduled'] ++; } } return $this->withJson($response, $output); } public function pending(ServerRequestInterface $request, ResponseInterface $response, Service $service): ResponseInterface { $pending = $service->getPending(); $output = [ 'total' => count($pending), 'jobs' => $pending ]; return $this->withJson($response, $output); } public function pendingCommands(ServerRequestInterface $request, ResponseInterface $response, Service $service): ResponseInterface { $body = $response->getBody(); $json = json_decode($body->getContents()); if (!isset($json->commands)) { throw new MissingArgument('commands', 'array', 'job commands'); } $output = [ 'commands' => $json->commands, 'total' => count($json->commands), 'pending' => [] ]; foreach ($json->commands as $command) { $pending = $service->getPendingByCommand($command); if (count($pending) === 0) { continue; } $output['pending'][$command] = $pending; } return $this->withJson($response, $output); } public function finish(ServerRequestInterface $request, ResponseInterface $response, Service $service, $job_id): ResponseInterface { $output = [ 'job_id' => $job_id, 'status' => $service->finish($job_id) ]; return $this->withJson($response, $output); } public function failed(ServerRequestInterface $request, ResponseInterface $response, Service $service, $job_id): ResponseInterface { $output = [ 'job_id' => $job_id, 'status' => $service->failed($job_id) ]; return $this->withJson($response, $output); } }