schedule is protected in others classes

This commit is contained in:
Henry Jordan
2020-06-09 14:45:12 +00:00
parent 7dadafab11
commit 1e0c55512a
2 changed files with 33 additions and 39 deletions

View File

@@ -7,6 +7,7 @@ use \Illuminate\Support\Carbon;
use Illuminate\Console\Scheduling\ScheduleRunCommand as BaseCommand; use Illuminate\Console\Scheduling\ScheduleRunCommand as BaseCommand;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
use ProcessMaker\BusinessModel\TaskSchedulerBM; use ProcessMaker\BusinessModel\TaskSchedulerBM;
use ProcessMaker\Model\TaskScheduler;
class ScheduleRunCommand extends BaseCommand class ScheduleRunCommand extends BaseCommand
{ {
@@ -45,7 +46,38 @@ class ScheduleRunCommand extends BaseCommand
$webApplication->setRootDir($this->option('processmakerPath')); $webApplication->setRootDir($this->option('processmakerPath'));
$webApplication->loadEnvironment($workspace, false); $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(); parent::handle();
} }
} }

View File

@@ -11,44 +11,6 @@ use ProcessMaker\Core\System;
class TaskSchedulerBM 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 * Return the records in Schedule Table by category
*/ */