Task scheduler
This commit is contained in:
253
workflow/engine/src/ProcessMaker/BusinessModel/TaskSchedulerBM.php
Executable file
253
workflow/engine/src/ProcessMaker/BusinessModel/TaskSchedulerBM.php
Executable file
@@ -0,0 +1,253 @@
|
||||
<?php
|
||||
namespace ProcessMaker\BusinessModel;
|
||||
|
||||
use ProcessMaker\Model\TaskScheduler;
|
||||
use \G;
|
||||
use ProcessMaker\Plugins\Interfaces\StepDetail;
|
||||
use ProcessMaker\Plugins\PluginRegistry;
|
||||
use \ProcessMaker\Util;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use ProcessMaker\Core\System;
|
||||
|
||||
class TaskSchedulerBM
|
||||
{
|
||||
public function executeTasks(){
|
||||
TaskScheduler::all()->each(function($p){
|
||||
if($p->isDue()){
|
||||
Log::info("EXECUTE::" . $p->title . " -->" . $p->expression);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static function getSchedule($category){
|
||||
$tasks = TaskScheduler::all();
|
||||
$count = $tasks->count();
|
||||
if($count == 0){
|
||||
TaskSchedulerBM::generateInitialData();
|
||||
$tasks = TaskScheduler::all();
|
||||
}
|
||||
if(is_null($category)){
|
||||
return $tasks;
|
||||
}else{
|
||||
return TaskScheduler::where('category', $category)->get();
|
||||
}
|
||||
}
|
||||
|
||||
public static function saveSchedule(array $request_data){
|
||||
$task = TaskScheduler::find($request_data['id']);
|
||||
if(isset($request_data['expression'])){
|
||||
$task->expression = $request_data['expression'];
|
||||
}
|
||||
if(isset($request_data['enable'])){
|
||||
$task->enable = $request_data['enable'];
|
||||
}
|
||||
if(isset($request_data['startingTime'])){
|
||||
$task->startingTime = $request_data['startingTime'];
|
||||
}
|
||||
if(isset($request_data['endingTime'])){
|
||||
$task->endingTime = $request_data['endingTime'];
|
||||
}
|
||||
if(isset($request_data['timezone'])){
|
||||
$task->timezone = $request_data['timezone'];
|
||||
}
|
||||
$task->save();
|
||||
return array();
|
||||
}
|
||||
|
||||
public static function generateInitialData(){
|
||||
$arraySystemConfiguration = System::getSystemConfiguration('', '', config("system.workspace"));
|
||||
$toSave = array();
|
||||
$services = array(
|
||||
array(
|
||||
"title" => "ProcessMaker Events",
|
||||
"service" => "events",
|
||||
"category" => "case_actions",
|
||||
"file" => "workflow/engine/bin/cron.php",
|
||||
"startingTime" => "0:00",
|
||||
"endingTime" => "23:59",
|
||||
"expression" => "* * * * *",
|
||||
"description" => "Unpauses any case whose pause time has expired"
|
||||
),
|
||||
array(
|
||||
"title" => "ProcessMaker Scheduler",
|
||||
"enable" => "1",
|
||||
"service" => "scheduler",
|
||||
"category" => "case_actions",
|
||||
"file" => "workflow/engine/bin/cron.php",
|
||||
"startingTime" => "0:00",
|
||||
"endingTime" => "23:59",
|
||||
"expression" => "* * */1 * *",
|
||||
"description" => "Unpauses any case whose pause time has expired"
|
||||
),
|
||||
array(
|
||||
"title" => "Unpause Cases",
|
||||
"enable" => "0",
|
||||
"service" => "unpause",
|
||||
"category" => "case_actions",
|
||||
"file" => "workflow/engine/bin/cron.php",
|
||||
"startingTime" => "0:00",
|
||||
"endingTime" => "23:59",
|
||||
"expression" => "* */1 * * *",
|
||||
"description" => "Unpauses any case whose pause time has expired"
|
||||
),
|
||||
array(
|
||||
"title" => "Case Emails",
|
||||
"enable" => "1",
|
||||
"service" => "emails",
|
||||
"category" => "emails_notifications",
|
||||
"file" => "workflow/engine/bin/cron.php",
|
||||
"startingTime" => "0:00",
|
||||
"endingTime" => "23:59",
|
||||
"expression" => "*/5 * * * *",
|
||||
"description" => "Task, triggers, and actions by email notifications"
|
||||
),
|
||||
array(
|
||||
"title" => "ProcessMaker Plugins",
|
||||
"enable" => "0",
|
||||
"service" => "plugins",
|
||||
"category" => "plugins",
|
||||
"file" => "workflow/engine/bin/cron.php",
|
||||
"startingTime" => "0:00",
|
||||
"endingTime" => "23:59",
|
||||
"expression" => "* * */1 * *",
|
||||
"description" => "Custom plugins execution"
|
||||
),
|
||||
array(
|
||||
"title" => "Calculate the elapsed time",
|
||||
"service" => "calculate",
|
||||
"category" => "case_actions",
|
||||
"file" => "workflow/engine/bin/cron.php",
|
||||
"startingTime" => "0:00",
|
||||
"endingTime" => "23:59",
|
||||
"expression" => "* * */1 * *",
|
||||
"description" => 'Calculates the elapsed time "according to the configured calendar" of all open tasks in active cases)'
|
||||
),
|
||||
array(
|
||||
"title" => "Calculate App data",
|
||||
"service" => "calculateapp",
|
||||
"category" => "case_actions",
|
||||
"file" => "workflow/engine/bin/cron.php",
|
||||
"startingTime" => "0:00",
|
||||
"endingTime" => "23:59",
|
||||
"expression" => "* * */1 * *",
|
||||
"description" => 'Calculates the elapsed time "according to the configured calendar" of all open tasks in active cases)'
|
||||
),
|
||||
array(
|
||||
"title" => "Unassigned Case",
|
||||
"service" => "unassigned-case",
|
||||
"category" => "case_actions",
|
||||
"file" => "workflow/engine/bin/cron.php",
|
||||
"startingTime" => "0:00",
|
||||
"endingTime" => "23:59",
|
||||
"expression" => "* */1 * * *",
|
||||
"description" => 'Run the trigger for self-service cases that have a configured timeout setting)'
|
||||
),
|
||||
array(
|
||||
"title" => "Clean self service tables",
|
||||
"service" => "clean-self-service-tables",
|
||||
"category" => "case_actions",
|
||||
"file" => "workflow/engine/bin/cron.php",
|
||||
"startingTime" => "0:00",
|
||||
"endingTime" => "23:59",
|
||||
"expression" => "* * */1 * *",
|
||||
"description" => 'Clean unused records for Self-Service Value-Based feature. It is a maintenance command'
|
||||
),
|
||||
array(
|
||||
"title" => "Report by Users",
|
||||
"enable" => "0",
|
||||
"service" => "report_by_user",
|
||||
"category" => "case_actions",
|
||||
"file" => "workflow/engine/bin/cron.php",
|
||||
"startingTime" => "0:00",
|
||||
"endingTime" => "23:59",
|
||||
"expression" => "* */1 * * *",
|
||||
"description" => "Report by Users"
|
||||
|
||||
),
|
||||
array(
|
||||
"title" => "Report by process",
|
||||
"enable" => "0",
|
||||
"service" => "report_by_process",
|
||||
"category" => "case_actions",
|
||||
"file" => "workflow/engine/bin/cron.php",
|
||||
"startingTime" => "0:00",
|
||||
"endingTime" => "23:59",
|
||||
"expression" => "* */1 * * *",
|
||||
"description" => "Report by process"
|
||||
),
|
||||
array(
|
||||
"title" => "Message Events",
|
||||
"enable" => "1",
|
||||
"service" => "",
|
||||
"category" => "emails_notifications",
|
||||
"file" => "workflow/engine/bin/messageeventcron.php",
|
||||
"startingTime" => "0:00",
|
||||
"endingTime" => "23:59",
|
||||
"expression" => "*/5 * * * *",
|
||||
"description" => "Intermediate and End Email Event"
|
||||
),
|
||||
array(
|
||||
"title" => "ProcessMaker timer event cron",
|
||||
"enable" => "0",
|
||||
"service" => "",
|
||||
"category" => "case_actions",
|
||||
"file" => "workflow/engine/bin/timereventcron.php",
|
||||
"startingTime" => "0:00",
|
||||
"endingTime" => "23:59",
|
||||
"expression" => "* * */1 * *",
|
||||
"description" => "ProcessMaker timer event cron"
|
||||
),
|
||||
array(
|
||||
"title" => "ProcessMaker LDAP cron",
|
||||
"enable" => "0",
|
||||
"service" => "",
|
||||
"category" => "processmaker_sync",
|
||||
"file" => "workflow/engine/bin/ldapcron.php",
|
||||
"startingTime" => "0:00",
|
||||
"endingTime" => "23:59",
|
||||
"expression" => "* * */1 * *",
|
||||
"description" => "Synchronize Advance LDAP Attributes from their settings"
|
||||
),
|
||||
array(
|
||||
"title" => "Send notifications",
|
||||
"enable" => "1",
|
||||
"service" => "",
|
||||
"category" => "emails_notifications",
|
||||
"file" => "workflow/engine/bin/sendnotificationscron.php",
|
||||
"startingTime" => "0:00",
|
||||
"endingTime" => "23:59",
|
||||
"expression" => "*/5 * * * *",
|
||||
"description" => "ProcessMaker Mobile Notifications"
|
||||
),
|
||||
array(
|
||||
"title" => "Action by emails response",
|
||||
"enable" => "1",
|
||||
"service" => "",
|
||||
"category" => "emails_notifications",
|
||||
"file" => "workflow/engine/bin/actionsByEmailEmailResponse.php",
|
||||
"startingTime" => "0:00",
|
||||
"endingTime" => "23:59",
|
||||
"expression" => "*/5 * * * *",
|
||||
"description" => "Actions by email response account email revision"
|
||||
)
|
||||
);
|
||||
|
||||
for($i = 0; $i < count($services); ++$i) {
|
||||
$task = new TaskScheduler;
|
||||
$task->title = $services[$i]["title"];
|
||||
$task->category = $services[$i]["category"];
|
||||
$task->description = $services[$i]["description"];
|
||||
$task->startingTime = $services[$i]["startingTime"];
|
||||
$task->endingTime = $services[$i]["endingTime"];
|
||||
$task->body = 'su -s /bin/sh -c "php '. PATH_TRUNK . $services[$i]["file"] . " " . $services[$i]["service"] . ' +w' . config("system.workspace") . ' +force"';
|
||||
$task->expression = $services[$i]["expression"];
|
||||
$task->type = "shell";
|
||||
$task->system = 1;
|
||||
$task->timezone = $arraySystemConfiguration['time_zone'];
|
||||
$task->enable = $services[$i]["enable"];
|
||||
$task->startingTime = "0:00";
|
||||
$task->endingTime = "23:59";
|
||||
$task->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user