mirror of
https://github.com/getgrav/grav.git
synced 2026-05-07 06:06:16 +02:00
Ability to force-run a Scheduled job #2720
This commit is contained in:
@@ -1,3 +1,9 @@
|
||||
# v1.7.0-rc.1
|
||||
## mm/dd/2019
|
||||
|
||||
1. [](#new)
|
||||
* Added new `-r <job-id>` option for Schduler CLI command to force-run a job [#2720](https://github.com/getgrav/grav/issues/2720)
|
||||
|
||||
# v1.7.0-rc.1
|
||||
## 11/06/2019
|
||||
|
||||
|
||||
@@ -123,6 +123,23 @@ class Scheduler
|
||||
return array_merge($background, $foreground);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a specific Job based on id
|
||||
*
|
||||
* @param $jobid
|
||||
* @return Job|null
|
||||
*/
|
||||
public function getJob($jobid)
|
||||
{
|
||||
$all = $this->getAllJobs();
|
||||
foreach ($all as $job) {
|
||||
if ($jobid == $job->getId()) {
|
||||
return $job;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Queues a PHP function execution.
|
||||
*
|
||||
|
||||
@@ -11,6 +11,7 @@ namespace Grav\Console\Cli;
|
||||
|
||||
use Cron\CronExpression;
|
||||
use Grav\Common\Grav;
|
||||
use Grav\Common\Scheduler\Job;
|
||||
use Grav\Common\Utils;
|
||||
use Grav\Common\Scheduler\Scheduler;
|
||||
use Grav\Console\ConsoleCommand;
|
||||
@@ -43,6 +44,12 @@ class SchedulerCommand extends ConsoleCommand
|
||||
InputOption::VALUE_NONE,
|
||||
'Show Job Details'
|
||||
)
|
||||
->addOption(
|
||||
'run',
|
||||
'r',
|
||||
InputOption::VALUE_REQUIRED,
|
||||
'Force run a job with a specific Job ID'
|
||||
)
|
||||
->setDescription('Run the Grav Scheduler. Best when integrated with system cron')
|
||||
->setHelp("Running without any options will force the Scheduler to run through it's jobs and process them");
|
||||
}
|
||||
@@ -149,6 +156,29 @@ class SchedulerCommand extends ConsoleCommand
|
||||
|
||||
$table->setRows($rows);
|
||||
$table->render();
|
||||
} elseif ($jobid = $this->input->getOption('run')) {
|
||||
$io->title('Force Run Job: ' . $jobid);
|
||||
|
||||
/** @var Job $job */
|
||||
$job = $scheduler->getJob($jobid);
|
||||
|
||||
if ($job) {
|
||||
$job->inForeground()->run();
|
||||
|
||||
if ($job->isSuccessful()) {
|
||||
$io->success('Job ran successfully...');
|
||||
} else {
|
||||
$io->error('Job failed to run successfully...');
|
||||
}
|
||||
|
||||
$output = $job->getOutput();
|
||||
|
||||
if ($output) {
|
||||
$this->output->write($output);
|
||||
}
|
||||
} else {
|
||||
$io->error('Could not find a job with id: ' . $jobid);
|
||||
}
|
||||
} elseif ($this->input->getOption('install')) {
|
||||
$io->title('Install Scheduler');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user