diff --git a/app/Console/Commands/ScheduleRunCommand.php b/app/Console/Commands/ScheduleRunCommand.php index 234e08521..31abf4e53 100755 --- a/app/Console/Commands/ScheduleRunCommand.php +++ b/app/Console/Commands/ScheduleRunCommand.php @@ -7,6 +7,7 @@ use \Illuminate\Support\Carbon; use Illuminate\Console\Scheduling\ScheduleRunCommand as BaseCommand; use Illuminate\Support\Facades\Log; use ProcessMaker\BusinessModel\TaskSchedulerBM; +use ProcessMaker\Model\TaskScheduler; class ScheduleRunCommand extends BaseCommand { @@ -45,7 +46,38 @@ class ScheduleRunCommand extends BaseCommand $webApplication->setRootDir($this->option('processmakerPath')); $webApplication->loadEnvironment($workspace, false); } - TaskSchedulerBM::executeScheduler($this); + TaskScheduler::all()->each(function ($p) use ($that) { + $starting = isset($p->startingTime) ? $p->startingTime : "0:00"; + $ending = isset($p->startingTime) ? $p->endingTime : "23:59"; + $timezone = isset($p->timezone) && $p->timezone != ""? $p->timezone: date_default_timezone_get(); + $that->schedule->exec($p->body)->cron($p->expression)->between($starting, $ending)->timezone($timezone)->when(function () use ($p) { + $now = Carbon::now(); + $result = false; + $datework = Carbon::createFromFormat('Y-m-d H:i:s', $p->last_update); + if (isset($p->everyOn)) { + switch ($p->interval) { + case "day": + $interval = $now->diffInDays($datework); + $result = ($interval !== 0 && ($interval % intval($p->everyOn)) == 0); + break; + case "week": + $interval = $now->diffInDays($datework); + $result = ($interval !== 0 && $interval % (intval($p->everyOn) * 7) == 0); + break; + case "month": + $interval = $now->diffInMonths($datework); + $result = ($interval !== 0 && $interval % intval($p->everyOn) == 0); + break; + case "year": + $interval = $now->diffInYears($datework); + $result = ($interval !== 0 && $interval % intval($p->everyOn) == 0); + break; + } + return $result; + } + return true; + }); + }); parent::handle(); } } diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/TaskSchedulerBM.php b/workflow/engine/src/ProcessMaker/BusinessModel/TaskSchedulerBM.php index 4c4d8f2cf..06f477fb6 100755 --- a/workflow/engine/src/ProcessMaker/BusinessModel/TaskSchedulerBM.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/TaskSchedulerBM.php @@ -11,44 +11,6 @@ use ProcessMaker\Core\System; class TaskSchedulerBM { - /** - * Execute the records with Laravel Task Scheduler - */ - public static function executeScheduler($that){ - TaskScheduler::all()->each(function ($p) use ($that) { - $starting = isset($p->startingTime) ? $p->startingTime : "0:00"; - $ending = isset($p->startingTime) ? $p->endingTime : "23:59"; - $timezone = isset($p->timezone) && $p->timezone != ""? $p->timezone: date_default_timezone_get(); - $that->schedule->exec($p->body)->cron($p->expression)->between($starting, $ending)->timezone($timezone)->when(function () use ($p) { - $now = Carbon::now(); - $result = false; - $datework = Carbon::createFromFormat('Y-m-d H:i:s', $p->last_update); - if (isset($p->everyOn)) { - switch ($p->interval) { - case "day": - $interval = $now->diffInDays($datework); - $result = ($interval !== 0 && ($interval % intval($p->everyOn)) == 0); - break; - case "week": - $interval = $now->diffInDays($datework); - $result = ($interval !== 0 && $interval % (intval($p->everyOn) * 7) == 0); - break; - case "month": - $interval = $now->diffInMonths($datework); - $result = ($interval !== 0 && $interval % intval($p->everyOn) == 0); - break; - case "year": - $interval = $now->diffInYears($datework); - $result = ($interval !== 0 && $interval % intval($p->everyOn) == 0); - break; - } - return $result; - } - return true; - }); - }); - } - /** * Return the records in Schedule Table by category */