Jobby\Jobby::add PHP Method

add() public method

Add a job.
public add ( string $job, array $config )
$job string
$config array
    public function add($job, array $config)
    {
        if (empty($config['schedule'])) {
            throw new Exception("'schedule' is required for '{$job}' job");
        }
        if (!(isset($config['command']) xor isset($config['closure']))) {
            throw new Exception("Either 'command' or 'closure' is required for '{$job}' job");
        }
        if (isset($config['command']) && ($config['command'] instanceof Closure || $config['command'] instanceof SerializableClosure)) {
            $config['closure'] = $config['command'];
            unset($config['command']);
            if ($config['closure'] instanceof SerializableClosure) {
                $config['closure'] = $config['closure']->getClosure();
            }
        }
        $config = array_merge($this->config, $config);
        $this->jobs[$job] = $config;
    }

Usage Example

 /**
  * 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;
 }
All Usage Examples Of Jobby\Jobby::add