PMCORE-2369-A Kpi Report by process and Report by user does not work and the error is displayed on the taskscheduler log

This commit is contained in:
Roly Gutierrez
2021-09-24 14:29:51 -04:00
parent a1ddfe3b4d
commit acc75b3fd5
2 changed files with 21 additions and 23 deletions

View File

@@ -54,6 +54,23 @@ class ScheduleRunCommand extends BaseCommand
if (!$win) { if (!$win) {
$body = str_replace(" -c"," " . $user . " -c", $p->body); $body = str_replace(" -c"," " . $user . " -c", $p->body);
} }
//for init date and finish date parameters
if (strpos($body, "report_by_user") !== false || strpos($body, "report_by_process") !== false) {
//remove if the command is old and contains an incorrect definition of the date
$body = preg_replace("/\s\+init-date\"[0-9\-\s:]+\"/", "", $body);
$body = preg_replace("/\s\+finish-date\"[0-9\-\s:]+\"/", "", $body);
//the start date must be one month back from the current date.
$currentDate = date("Y-m-d H:i:s");
$oneMonthAgo = $currentDate . " -1 month";
$timestamp = strtotime($oneMonthAgo);
$oneMonthAgo = date("Y-m-d H:i:s", $timestamp);
$body = str_replace("report_by_user", "report_by_user +init-date'{$oneMonthAgo}' +finish-date'{$currentDate}'", $body);
$body = str_replace("report_by_process", "report_by_process +init-date'{$oneMonthAgo}' +finish-date'{$currentDate}'", $body);
}
$schedule = $that->schedule->exec($body)->cron($p->expression)->between($starting, $ending)->timezone($timezone)->when(function () use ($p) { $schedule = $that->schedule->exec($body)->cron($p->expression)->between($starting, $ending)->timezone($timezone)->when(function () use ($p) {
$now = Carbon::now(); $now = Carbon::now();
$result = false; $result = false;

View File

@@ -172,9 +172,7 @@ class TaskSchedulerBM
"everyOn" => "1", "everyOn" => "1",
"interval" => "week", "interval" => "week",
"expression" => "*/10 * * * 0,1,2,3,4,5,6", "expression" => "*/10 * * * 0,1,2,3,4,5,6",
"description" => "ID_TASK_SCHEDULER_REPORT_USERS_DESC", "description" => "ID_TASK_SCHEDULER_REPORT_USERS_DESC"
"initDate" => "+init-date",
"finishDate" => "+finish-date"
], ],
[ [
"title" => "ID_TASK_SCHEDULER_REPORT_PROCESS", "title" => "ID_TASK_SCHEDULER_REPORT_PROCESS",
@@ -191,9 +189,7 @@ class TaskSchedulerBM
"everyOn" => "1", "everyOn" => "1",
"interval" => "week", "interval" => "week",
"expression" => "*/10 * * * 0,1,2,3,4,5,6", "expression" => "*/10 * * * 0,1,2,3,4,5,6",
"description" => "ID_TASK_SCHEDULER_CALCULATE_APP_DESC", "description" => "ID_TASK_SCHEDULER_CALCULATE_APP_DESC"
"initDate" => "+init-date",
"finishDate" => "+finish-date"
], ],
[ [
"title" => "ID_TASK_SCHEDULER_LDAP", "title" => "ID_TASK_SCHEDULER_LDAP",
@@ -283,25 +279,10 @@ class TaskSchedulerBM
$task->description = $service["description"]; $task->description = $service["description"];
$task->startingTime = $service["startingTime"]; $task->startingTime = $service["startingTime"];
$task->endingTime = $service["endingTime"]; $task->endingTime = $service["endingTime"];
$activity = $service["service"];
//for init date and finish date parameters
$currentDate = date("Y-m-d H:i:s");
$setOfActivities = ["report_by_user", "report_by_process"];
if (!empty($service["initDate"]) && in_array($activity, $setOfActivities)) {
$oneMonthAgo = $currentDate . " -1 month";
$timestamp = strtotime($oneMonthAgo);
$oneMonthAgo = date("Y-m-d H:i:s", $timestamp);
$activity = $activity . ' ' . $service["initDate"] . '"' . $oneMonthAgo . '"';
}
if (!empty($service["finishDate"]) && in_array($activity, $setOfActivities)) {
$activity = $activity . ' ' . $service["initDate"] . '"' . $currentDate . '"';
}
if ($win) { if ($win) {
$task->body = 'php "' . PATH_TRUNK . $service["filew"] . '" ' . $activity . ' +w' . config("system.workspace") . ' +force +async'; $task->body = 'php "' . PATH_TRUNK . $service["filew"] . '" ' . $service["service"] . ' +w' . config("system.workspace") . ' +force +async';
} else { } else {
$task->body = 'su -s /bin/sh -c "php ' . PATH_TRUNK . $service["file"] . " " . $activity . ' +w' . config("system.workspace") . ' +force +async"'; $task->body = 'su -s /bin/sh -c "php ' . PATH_TRUNK . $service["file"] . " " . $service["service"] . ' +w' . config("system.workspace") . ' +force +async"';
} }
$task->expression = $service["expression"]; $task->expression = $service["expression"];
$task->type = "shell"; $task->type = "shell";