Beispiel #1
0
 /**
  * {@inheritDoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     try {
         $this->init($input, $output);
         $logger = $this->buildLogger();
         $logger->log(Logger::INFO, 'Beginning tasker.');
         $config = Tasker\Common::getConfigArray($this->options['config_file']);
         foreach ($config['tasker']['tasks'] as $task) {
             $taskObj = new Tasker\Task($task['name'], $task['time'], $logger);
             if (isset($task['class'])) {
                 $taskObj->setClass($task['class']);
             }
             if (isset($task['command'])) {
                 $taskObj->setCommand($task['command']);
             }
             $tasks[] = $taskObj;
         }
         $logger->log(Logger::DEBUG, 'Calling on Shideon\\Tasker\\Tasker');
         $tasker = new Tasker\Tasker($tasks, $logger);
         // for passing to tasker->run(). our lib requires these values
         // but extenders may not need them so they're optional
         // and this is determined by their existence in the command
         // options.
         $configFile = null;
         $logFile = null;
         $logLevel = null;
         $requiredOptions = $this->getRequiredOptions();
         if (array_search('config_file', $requiredOptions) !== false) {
             $configFile = $this->options['config_file'];
         }
         if (array_search('log_file', $requiredOptions) !== false) {
             $logFile = $this->options['log_file'];
             $logLevel = $this->options['log_level'];
         }
         $output->write($tasker->run($configFile, $logFile, $logLevel));
     } catch (\Exception $e) {
         // if we don't have a logger (due to exception being thrown before
         // it's instantiatied) then attempt to build one. ignore its
         // exceptions.
         if (!isset($logger) || !$logger instanceof Logger) {
             try {
                 $logger = $this->buildLogger();
             } catch (\Exception $e) {
                 // ignore
             }
         }
         if (isset($logger) && $logger instanceof Logger) {
             $logger->log(Logger::CRITICAL, "Running task '" . $this->options['task_name'] . "' encountered exception in " . get_class($this), [$e, 'trace' => $e->getTraceAsString()]);
         }
         throw $e;
     }
 }
Beispiel #2
0
 /**
  * {@inheritDoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     try {
         $this->init($input, $output);
         $logger = $this->buildLogger();
         $logger->log(Logger::DEBUG, "Running task '" . $this->options['task_name'] . "'. Calling Shideon\\Tasker\\Task.");
         $config = Tasker\Common::getConfigArray($this->options['config_file']);
         // get the task we're working with
         foreach ($config['tasker']['tasks'] as $task) {
             if (isset($task['name']) && $task['name'] == $this->options['task_name']) {
                 Tasker\Task::Factory($this->options['task_name'], '', $logger)->setFromArray($task)->callClass();
                 break;
             }
         }
     } catch (\Exception $e) {
         // if we don't have a logger (due to exception being thrown before
         // it's instantiatied) then attempt to build one. ignore its
         // exceptions.
         if (!isset($logger) || !$logger instanceof Logger) {
             try {
                 $logger = $this->buildLogger();
             } catch (\Exception $e) {
                 // ignore
             }
         }
         if (isset($logger) && $logger instanceof Logger) {
             $logger->log(Logger::CRITICAL, "Running task '" . $this->options['task_name'] . "' encountered exception in " . get_class($this), [$e, 'trace' => $e->getTraceAsString()]);
         }
         throw $e;
     }
 }