/** * Execute the job * * @return string - The output of the executed job */ public function exec() { $this->compiled = $this->build(); if (is_callable($this->compiled)) { $return = call_user_func($this->command, $this->args); foreach ($this->outputs as $output) { Filesystem::write($return, $output, $this->mode); } } else { $return = exec($this->compiled); } if ($this->emails) { $this->sendEmails(); } return $return; }
/** * Run the scheduled jobs * * @return array - The output of the executed jobs */ public function run() { $output = []; // First reorder the cronjobs $this->jobsInBackgroundFirst(); foreach ($this->jobs as $job) { $job->setup($this->config); // Check if job is due and if it should prevent overlapping if ($job->isDue()) { if ($job->preventOverlap() !== false) { // If overlapping, skip job execution if (!$this->jobCanRun($job)) { continue; } // Create lock file for this job to prevent overlap $lockFile = implode('/', [$this->getTempDir(), md5($job->getCommand()) . '.lock']); Filesystem::write('', $lockFile); // Sets the file to remove after the execution $job->removeLockAfterExec($lockFile); // Sets the job to run in foreground $job->runInForeground(); } $output[] = $job->exec(); $this->executed[] = $job; } } return $output; }