Skip to content

Commit bf587d1

Browse files
committed
Add job validation and new scheduling method scheduleDateJob
1 parent 2ae98d8 commit bf587d1

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

ProcessMaker/Managers/TaskSchedulerManager.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Illuminate\Support\Facades\DB;
1313
use Illuminate\Support\Facades\Log;
1414
use Illuminate\Support\Facades\Schema;
15+
use InvalidArgumentException;
1516
use PDOException;
1617
use ProcessMaker\Facades\WorkflowManager;
1718
use ProcessMaker\Jobs\StartEventConditional;
@@ -574,6 +575,9 @@ public function scheduleCycle(
574575
*/
575576
public function scheduleCycleJob($interval, array $config): ScheduledTask
576577
{
578+
if (!isset($config['job'])) {
579+
throw new InvalidArgumentException('$config["job"] is required');
580+
}
577581
$configuration = [
578582
'type' => 'TimeCycle',
579583
'interval' => $interval,
@@ -590,6 +594,33 @@ public function scheduleCycleJob($interval, array $config): ScheduledTask
590594
return $scheduledTask;
591595
}
592596

597+
/**
598+
* Schedule a job for a specific datetime
599+
*
600+
* @param string $datetime in ISO-8601 format
601+
* @param array $config configuration
602+
*
603+
* @return ScheduledTask
604+
*/
605+
public function scheduleDateJob($datetime, array $config): ScheduledTask
606+
{
607+
if (!isset($config['job'])) {
608+
throw new InvalidArgumentException('$config["job"] is required');
609+
}
610+
$configuration = [
611+
'type' => 'TimeDate',
612+
'date' => $datetime,
613+
...$config,
614+
];
615+
$scheduledTask = new ScheduledTask();
616+
$scheduledTask->configuration = json_encode($configuration);
617+
$scheduledTask->type = 'SCHEDULED_JOB';
618+
$scheduledTask->last_execution = null;
619+
$scheduledTask->save();
620+
621+
return $scheduledTask;
622+
}
623+
593624
/**
594625
* Schedule a job execution after a time duration for the given BPMN element,
595626
* event definition and an optional Token object

0 commit comments

Comments
 (0)