Newscoop\SchedulerServiceInterface::registerJob PHP Method

registerJob() public method

Add cron job details to database
public registerJob ( string $jobName, array $config ) : void
$jobName string Cron job name
$config array Array with job configuration - string $command The job to run (either a shell command or anonymous PHP function) - string $schedule Crontab schedule format (`man -s 5 crontab`) - boolean $enabled Run this job at scheduled times - boolean $debug Send `jobby` internal messages to 'debug.log' - string $dateFormat Format for dates on `jobby` log messages - string $output Redirect `stdout` and `stderr` to this file - string $runOnHost Run jobs only on this hostname - string $environment Development environment for this job - string $runAs Run as this user, if crontab user has `sudo` privileges
return void
    public function registerJob($jobName, array $config);

Usage Example

示例#1
0
 /**
  * Save newscoop cronjobs in user cronjob file
  *
  * @param  SchedulerService $scheduler Cron job scheduler service
  * @return bolean
  */
 public function saveCronjobs(SchedulerServiceInterface $scheduler)
 {
     $binDirectory = realpath($this->newscoopDir . '/bin');
     $appDirectory = realpath($this->newscoopDir . '/application/console');
     $scheduler->registerJob("Autopublish pending issues and articles", array('command' => $binDirectory . '/newscoop-autopublish', 'schedule' => '* * * * *'));
     $scheduler->registerJob("Runs Newscoop Indexer - articles indexing", array('command' => $binDirectory . '/newscoop-indexer --silent', 'schedule' => '0 */4 * * *'));
     $scheduler->registerJob("Send Newscoop subscriptions notifications", array('command' => $binDirectory . '/subscription-notifier', 'schedule' => '0 */8 * * *'));
     $scheduler->registerJob("Send Newscoop events notifications", array('command' => $binDirectory . '/events-notifier', 'schedule' => '*/2 * * * *'));
     $scheduler->registerJob("Remove old statistics from Newscoop database", array('command' => $binDirectory . '/newscoop-statistics', 'schedule' => '0 */4 * * *'));
     $scheduler->registerJob("Send Newscoop stats to Sourcefabric", array('command' => $binDirectory . '/newscoop-stats', 'schedule' => '0 5 * * *'));
     $scheduler->registerJob("Remove obsolete pending users data", array('command' => $appDirectory . ' user:garbage', 'schedule' => '30 0 * * *'));
     $scheduler->registerJob("Display the last 7 days logged actions when going to Configure -> Logs. All the rest are stored in newscoop-audit.log.", array('command' => $appDirectory . ' log:maintenance', 'schedule' => '30 1 * * *', 'enabled' => false, 'detailsUrl' => 'http://sourcefabric.booktype.pro/newscoop-42-for-journalists-and-editors/log-file-maintenance/'));
     $crontab = new Crontab();
     $job = new Job();
     $job->setMinute('*')->setHour('*')->setDayOfMonth('*')->setMonth('*')->setDayOfWeek('*')->setCommand('php ' . $appDirectory . ' scheduler:run');
     $crontab->addJob($job);
     $crontab->write();
     return true;
 }