Exemplo n.º 1
0
 /**
  * Returns live informations about the given task.
  *
  * @return array
  */
 public function getTask(Task $task, $throwException = false)
 {
     try {
         $data = $this->notifier->notify(Notifier::MESSAGE_INFORMATIONS, 2);
     } catch (RuntimeException $e) {
         if ($throwException) {
             throw $e;
         }
         $data = [];
     }
     $taskData = isset($data['jobs']) && isset($data['jobs'][$task->getId()]) ? $data['jobs'][$task->getId()] : [];
     return ['configuration' => $task->getStatus(), 'actual' => isset($taskData['status']) ? $taskData['status'] : Task::STATUS_STOPPED, 'process-id' => isset($taskData['process-id']) ? $taskData['process-id'] : null];
 }
Exemplo n.º 2
0
 public function entityToTask(TaskEntity $task)
 {
     $name = $task->getId();
     $arguments = ['exec', $this->phpExec];
     if ($this->phpConf) {
         $arguments[] = '-c';
         $arguments[] = $this->phpConf;
     }
     $arguments[] = '-f';
     $arguments[] = $this->root . '/bin/console';
     $arguments[] = '--';
     $arguments[] = '-q';
     $arguments[] = 'task-manager:task:run';
     $arguments[] = $task->getId();
     $arguments[] = '--listen-signal';
     $arguments[] = '--max-duration';
     $arguments[] = '1800';
     $arguments[] = '--max-memory';
     $arguments[] = 128 << 20;
     $builder = ProcessBuilder::create($arguments);
     $builder->setTimeout(0);
     return new Task($task, $name, $task->isSingleRun() ? 1 : INF, $builder->getProcess());
 }
 /**
  * {@inheritDoc}
  */
 public function getId()
 {
     if ($this->__isInitialized__ === false) {
         return (int) parent::getId();
     }
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getId', array());
     return parent::getId();
 }
Exemplo n.º 4
0
 private function formatTask(Task $task, $data)
 {
     $taskData = isset($data['jobs']) && isset($data['jobs'][$task->getId()]) ? $data['jobs'][$task->getId()] : [];
     return ['configuration' => $task->getStatus(), 'actual' => isset($taskData['status']) ? $taskData['status'] : Task::STATUS_STOPPED, 'process-id' => isset($taskData['process-id']) ? $taskData['process-id'] : null];
 }
Exemplo n.º 5
0
 /**
  * {@inheritdoc}
  */
 public function getPath()
 {
     return sprintf('%s/task_%d.log', $this->root, $this->task->getId());
 }
 public function getTask(Request $request, Task $task)
 {
     if (false === $this->app['phraseanet.configuration']['main']['task-manager']['enabled']) {
         throw new RuntimeException('The use of the task manager is disabled on this instance.');
     }
     if ('json' === $request->getContentType()) {
         return $this->app->json(array_replace(['id' => $task->getId(), 'name' => $task->getName(), 'urls' => $this->getTaskResourceUrls($task->getId())], $this->getLiveInformationRequest()->getTask($task)));
     }
     $editor = $this->getJobFactory()->create($task->getJobId())->getEditor();
     $form = $this->app->form(new TaskForm());
     $form->setData($task);
     return $this->render($editor->getTemplatePath(), ['task' => $task, 'form' => $form->createView(), 'view' => 'XML']);
 }
Exemplo n.º 7
0
 public function getTask(Application $app, Request $request, Task $task)
 {
     if ('json' === $request->getContentType()) {
         return $app->json(array_replace(['id' => $task->getId(), 'name' => $task->getName(), 'urls' => $this->getTaskResourceUrls($app, $task->getId())], $app['task-manager.live-information']->getTask($task)));
     }
     $editor = $app['task-manager.job-factory']->create($task->getJobId())->getEditor();
     $form = $app->form(new TaskForm());
     $form->setData($task);
     return $app['twig']->render($editor->getTemplatePath(), ['task' => $task, 'form' => $form->createView(), 'view' => 'XML']);
 }