add() public méthode

Add a job.
public add ( string $job, array $config )
$job string
$config array
 /**
  * Jobby scheduler entry point
  */
 public function actionRun()
 {
     $jobby = new Jobby();
     $tasks = $this->getTasks();
     /** @var JobbyModelInterface[] $tasks */
     foreach ($tasks as $task) {
         $output = $task->getJobbyOutput();
         $jobby->add($task->getPrimaryKey(), ['command' => $task->getJobbyCommand(), 'schedule' => $task->getJobbySchedule(), 'output' => $output ? $output : null, 'enabled' => $task->getJobbyEnabled(), 'debug' => false]);
     }
     $jobby->run();
     echo count($tasks) . ' jobby tasks found' . PHP_EOL;
 }
Exemple #2
0
 /**
  * Register all of our tasks with our job runner.
  *
  * @param \Jobby\Jobby $runner The Jobby instance to bind these tasks to.
  * @param array $task_list A list of tasks to register.
  */
 private function register_tasks(\Jobby\Jobby $runner, $task_list)
 {
     foreach ($task_list as $task) {
         $task_class = $this->crony_job_namespace . '\\' . $task;
         // Per the interface...
         $task_config = call_user_func($task_class . '::config');
         // If there's no command registered in the configuration, we'll bind an anonymous function to
         // run our specified task.
         if (!isset($task_config['command'])) {
             $task_config['command'] = function () use($task_class) {
                 return call_user_func($task_class . '::run');
             };
         }
         $runner->add($task, $task_config);
     }
 }
Exemple #3
0
 public function testShouldFailIfMaxRuntimeExceeded()
 {
     $jobby = new Jobby();
     $jobby->add('slow job', ['command' => 'sleep 4', 'schedule' => '* * * * *', 'maxRuntime' => 1, 'output' => $this->logFile]);
     $jobby->run();
     sleep(2);
     $jobby->run();
     sleep(1);
     $this->assertContains('ERROR: MaxRuntime of 1 secs exceeded!', $this->getLogContent());
 }
Exemple #4
0
 public function testShouldFailIfMaxRuntimeExceeded()
 {
     if ($this->helper->getPlatform() === Helper::WINDOWS) {
         $this->markTestSkipped("'maxRuntime' is not supported on Windows");
     }
     $jobby = new Jobby();
     $jobby->add('slow job', ['command' => 'sleep 4', 'schedule' => '* * * * *', 'maxRuntime' => 1, 'output' => $this->logFile]);
     $jobby->run();
     sleep(2);
     $jobby->run();
     sleep(2);
     $this->assertContains('ERROR: MaxRuntime of 1 secs exceeded!', $this->getLogContent());
 }