/** * @Extra\Route( * "/export", * name="weaving_the_web_api_export_perspectives", * options={"expose"=true} * ) * @Extra\Method({"POST"}) */ public function exportAction() { $command = $this->exportPerspectiveCommand->getName(); if ($this->jobRepository->idleJobExistsForCommand($command)) { $message = $this->translator->trans('perspective.job.existing', [], 'perspective'); return new JsonResponse(['result' => $message, 'type' => 'error'], 429); } else { $token = $this->tokenStorage->getToken(); $job = $this->jobRepository->makeCommandJob($command, $token->getUser()); $this->entityManager->persist($job); $this->entityManager->flush(); $message = $this->translator->trans('perspective.job.submitted', [], 'perspective'); return new JsonResponse(['job' => ['entity' => 'job', 'id' => $job->getId(), 'Id' => $job->getId(), 'Status' => $this->jobRepository->getTranslatedStatusMessage($job), 'rlk_Output' => $job->getOutput(), 'Date' => $job->getCreatedAt()->format('Y-m-d H:i')], 'status' => $message, 'type' => 'success']); } }
/** * @param InputInterface $input * @param OutputInterface $output * @return int|mixed */ public function execute(InputInterface $input, OutputInterface $output) { $this->output = $output; try { $jobs = $this->repository->findIdleCommandJobs(); $this->runJobs($jobs); $outputMessage = $this->translator->trans('job.run.success', [], 'job'); $returnCode = 0; } catch (\Exception $exception) { $this->logger->error($exception->getMessage()); $returnCode = $exception->getCode(); $outputMessage = $this->translator->trans('job.run.error', [], 'job'); } $output->writeln($outputMessage); return $returnCode; }
/** * @Extra\Route( * "/{job}/output", * name="weaving_the_web_api_get_job_output", * requirements={"job": "\d+"}, * options={"expose"=true} * ) * @Extra\Method({"GET"}) * @Extra\ParamConverter( * "job", * class="WeavingTheWebApiBundle:Job" * ) * * @param JobInterface $job * @return JsonResponse */ public function getOutputAction(JobInterface $job) { $this->isGrantedJobAccess($job); return new JsonResponse($this->jobRepository->getOutputResponseContent($job)); }