public static function show()
 {
     return TasksTable::load(EcontrolLogger::create(false))->getTasks(true);
 }
Ejemplo n.º 2
0
 private function cycle()
 {
     // fire extender ready event
     $this->events->fire("extender", "VOID", $this);
     // dispatch signals (if multithread active)
     if ($this->getMultithreadMode()) {
         pcntl_signal_dispatch();
     }
     // if extender is paused (SIGINT), skip to extend
     if ($this->paused) {
         return;
     }
     // fix relative timestamp
     $this->timestamp = microtime(true);
     // fire tasktable event
     $this->tasks = $this->events->fire("extender.tasks", "TASKSTABLE", $this->tasks);
     // get the next planned activity interval
     $plans = Planner::get();
     if (!is_null($plans) and $this->timestamp < $plans) {
         // nothing to do right now, still waiting if in daemon mode
         $this->logger->info("Next planned job: " . date('c', $plans));
         $this->logger->notice("Extender completed\n");
         if ($this->getDaemonMode() === false) {
             $this->shutdown(true);
             self::end(0);
         }
         return;
     }
     // if no plan is retrieved, try to retrieve it from scheduler
     try {
         // get schedules and dispatch schedule event
         list($schedules, $planned) = Scheduler::getSchedules($this->logger, $this->timestamp);
         // write next planned activity interval
         if (!is_null($planned) and $planned != 0) {
             Planner::set($planned);
         }
         $scheduled = new Schedule();
         $scheduled->setSchedules($schedules);
         // expose the current shcedule via events
         $scheduled = $this->events->fire("extender.schedule", "SCHEDULE", $scheduled);
         // if no jobs in queue, exit gracefully
         if ($scheduled->howMany() == 0) {
             $this->logger->info("No jobs to process right now, exiting");
             $this->logger->notice("Extender completed\n");
             if ($this->getDaemonMode() === false) {
                 $this->shutdown(true);
                 self::end(0);
             }
             return;
         }
         // compose jobs
         foreach ($scheduled->getSchedules() as $schedule) {
             if ($this->tasks->isRegistered($schedule['task'])) {
                 $job = new Job();
                 $job->setName($schedule['name'])->setId($schedule['id'])->setParameters(unserialize($schedule['params']))->setTask($schedule['task'])->setClass($this->tasks->getClass($schedule['task']));
                 $this->runner->addJob($job);
             } else {
                 $this->logger->warning("Skipping job due to unknown task", array("ID" => $schedule['id'], "NAME" => $schedule['name'], "TASK" => $schedule['task']));
             }
         }
         // lauch runner
         $result = $this->runner->run();
         // free runner for next cycle
         $this->runner->free();
         // compose results
         $results = new JobsResult($result);
         // update schedules
         Scheduler::updateSchedules($this->logger, $result);
         // increment counters
         foreach ($result as $r) {
             if ($r[2]) {
                 $this->completed_processes++;
             } else {
                 $this->failed_processes++;
             }
         }
     } catch (Exception $e) {
         $this->logger->error($e->getMessage());
         if ($this->getDaemonMode() === false) {
             self::end(1);
         }
     }
     // fire result event
     $this->events->fire("extender.result", "VOID", $results);
     $this->logger->notice("Extender completed\n");
     // show summary (if -s)
     if ($this->summary_mode) {
         self::showSummary($this->timestamp, $result, $this->color);
     }
     Status::dump($this->timestamp_absolute, $this->parent_pid, $this->completed_processes, $this->failed_processes, $this->paused);
     if ($this->getDaemonMode() === false) {
         $this->shutdown(true);
         self::end(0);
     }
 }
 private static function getTasks()
 {
     return TasksTable::load(EcontrolLogger::create(false));
 }
Ejemplo n.º 4
0
 protected function setUp()
 {
     $debug = ExtenderLogger::create(false);
     $this->task = TasksTable::load($debug);
 }
Ejemplo n.º 5
0
 /**
  * econtrol constructor
  *
  */
 public function __construct()
 {
     // check if econtrol is running from cli
     if (Checks::cli() === false) {
         echo "Econtrol runs only in php-cli, exiting";
         self::end(1);
     }
     if (defined('EXTENDER_TIMEZONE')) {
         date_default_timezone_set(EXTENDER_TIMEZONE);
     }
     $this->color = new Console_Color2();
     $this->parser = new Console_CommandLine(array('description' => Version::getDescription(), 'version' => Version::getVersion()));
     // add verbose option
     $this->parser->addOption('verbose', array('short_name' => '-v', 'long_name' => '--verbose', 'description' => 'turn on verbose output', 'action' => 'StoreTrue'));
     // add debug option
     $this->parser->addOption('debug', array('short_name' => '-V', 'long_name' => '--debug', 'description' => 'turn on debug output', 'action' => 'StoreTrue'));
     try {
         $check_constants = Checks::constants();
         if ($check_constants !== true) {
             throw new ShellException($check_constants);
         }
         if (array_key_exists('V', getopt("V"))) {
             $verbose = 'DEBUG';
             echo $this->color->convert("\n%r(> Debug mode on <)%n\n");
         } else {
             if (array_key_exists('v', getopt("v"))) {
                 $verbose = 'NOTICE';
                 echo $this->color->convert("\n%y(> Verbose mode on <)%n\n");
             } else {
                 $verbose = false;
             }
         }
         $this->logger = EcontrolLogger::create($verbose);
         $this->tasks = TasksTable::load($this->logger);
         $this->controller = Controller::load($this->parser, $this->logger);
     } catch (Console_CommandLine_Exception $ce) {
         $this->parser->displayError($this->color->convert("\n\n%y" . $ce->getMessage() . "%n\n"));
         self::end(1);
     } catch (ShellException $se) {
         $this->parser->displayError($this->color->convert("\n\n%R" . $se->getMessage() . "%n\n"));
         self::end(1);
     } catch (Exception $e) {
         $this->parser->displayError($this->color->convert("\n\n%r" . $e->getMessage() . "%n\n"));
         self::end(1);
     }
 }