PMCORE-2189 Migrate to queue job - Cron File: cron.php - Activity: report_by_process
This commit is contained in:
committed by
Julio Cesar Laura Avendaño
parent
76f678ce80
commit
971de1fc81
@@ -338,4 +338,34 @@ class TaskTest extends TestCase
|
|||||||
Queue::assertPushed(TaskScheduler::class);
|
Queue::assertPushed(TaskScheduler::class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This test verify the fillReportByProcess activity method for synchronous and asynchronous execution.
|
||||||
|
* @test
|
||||||
|
* @covers ProcessMaker\TaskScheduler\Task::runTask()
|
||||||
|
* @covers ProcessMaker\TaskScheduler\Task::fillReportByProcess()
|
||||||
|
* @dataProvider asynchronousCases
|
||||||
|
*/
|
||||||
|
public function it_should_test_fillReportByProcess_method($asynchronous)
|
||||||
|
{
|
||||||
|
$task = new Task($asynchronous, '');
|
||||||
|
$dateInit = $this->faker->dateTime;
|
||||||
|
$dateFinish = $this->faker->dateTime;
|
||||||
|
|
||||||
|
//assert synchronous for cron file
|
||||||
|
if ($asynchronous === false) {
|
||||||
|
ob_start();
|
||||||
|
$task->fillReportByProcess($dateInit, $dateFinish);
|
||||||
|
$printing = ob_get_clean();
|
||||||
|
$this->assertRegExp("/User Reporting/", $printing);
|
||||||
|
}
|
||||||
|
|
||||||
|
//assert asynchronous for job process
|
||||||
|
if ($asynchronous === true) {
|
||||||
|
Queue::fake();
|
||||||
|
Queue::assertNothingPushed();
|
||||||
|
$task->fillReportByProcess($dateInit, $dateFinish);
|
||||||
|
Queue::assertPushed(TaskScheduler::class);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -317,10 +317,12 @@ try {
|
|||||||
$task->executePlugins();
|
$task->executePlugins();
|
||||||
}
|
}
|
||||||
/*----------------------------------********---------------------------------*/
|
/*----------------------------------********---------------------------------*/
|
||||||
if (empty($argvx) || strpos($argvx, "report_by_user") !== false) {
|
if (strpos($argvx, "report_by_user") !== false) {
|
||||||
$task->fillReportByUser($dateInit, $dateFinish);
|
$task->fillReportByUser($dateInit, $dateFinish);
|
||||||
}
|
}
|
||||||
fillReportByProcess();
|
if (strpos($argvx, "report_by_process") !== false) {
|
||||||
|
$task->fillReportByProcess($dateInit, $dateFinish);
|
||||||
|
}
|
||||||
synchronizeDrive();
|
synchronizeDrive();
|
||||||
synchronizeGmailLabels();
|
synchronizeGmailLabels();
|
||||||
/*----------------------------------********---------------------------------*/
|
/*----------------------------------********---------------------------------*/
|
||||||
@@ -589,37 +591,6 @@ function setExecutionResultMessage($m, $t = '')
|
|||||||
}
|
}
|
||||||
/*----------------------------------********---------------------------------*/
|
/*----------------------------------********---------------------------------*/
|
||||||
|
|
||||||
function fillReportByProcess()
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
global $argvx;
|
|
||||||
global $dateInit;
|
|
||||||
global $dateFinish;
|
|
||||||
|
|
||||||
if (strpos($argvx, "report_by_process") === false) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($dateInit == null) {
|
|
||||||
eprintln("You must enter the starting date.", "red");
|
|
||||||
eprintln('Example: +init-date"YYYY-MM-DD HH:MM:SS" +finish-date"YYYY-MM-DD HH:MM:SS"', "red");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$dateFinish = ($dateFinish != null) ? $dateFinish : date("Y-m-d H:i:s");
|
|
||||||
$appcv = new AppCacheView();
|
|
||||||
$appcv->setPathToAppCacheFiles(PATH_METHODS . 'setup' . PATH_SEP . 'setupSchemas' . PATH_SEP);
|
|
||||||
|
|
||||||
setExecutionMessage("Calculating data to fill the 'Process Reporting'...");
|
|
||||||
$appcv->fillReportByProcess($dateInit, $dateFinish);
|
|
||||||
setExecutionResultMessage("DONE");
|
|
||||||
} catch (Exception $e) {
|
|
||||||
setExecutionResultMessage("WITH ERRORS", "error");
|
|
||||||
eprintln(" '-" . $e->getMessage(), "red");
|
|
||||||
saveLog("fillReportByProcess", "error", "Error in fill report by process: " . $e->getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function synchronizeDrive()
|
function synchronizeDrive()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ use Criteria;
|
|||||||
use Exception;
|
use Exception;
|
||||||
use G;
|
use G;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
use ProcessMaker\Plugins\PluginRegistry;
|
|
||||||
use ProcessMaker\Core\JobsManager;
|
use ProcessMaker\Core\JobsManager;
|
||||||
|
use ProcessMaker\Plugins\PluginRegistry;
|
||||||
use Propel;
|
use Propel;
|
||||||
use ResultSet;
|
use ResultSet;
|
||||||
use SpoolRun;
|
use SpoolRun;
|
||||||
@@ -396,13 +396,12 @@ class Task
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This fills the report by user.
|
* This fills the report by user.
|
||||||
* @param datetime $dateInit
|
* @param string $dateInit
|
||||||
* @param datetime $dateFinish
|
* @param string $dateFinish
|
||||||
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function fillReportByUser($dateInit, $dateFinish)
|
public function fillReportByUser($dateInit, $dateFinish)
|
||||||
{
|
{
|
||||||
$job = function() use($dateInit, $dateFinish) {
|
|
||||||
try {
|
|
||||||
if ($dateInit == null) {
|
if ($dateInit == null) {
|
||||||
if ($this->asynchronous === false) {
|
if ($this->asynchronous === false) {
|
||||||
eprintln("You must enter the starting date.", "red");
|
eprintln("You must enter the starting date.", "red");
|
||||||
@@ -414,6 +413,8 @@ class Task
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
$job = function() use($dateInit, $dateFinish) {
|
||||||
|
try {
|
||||||
|
|
||||||
$dateFinish = ($dateFinish != null) ? $dateFinish : date("Y-m-d H:i:s");
|
$dateFinish = ($dateFinish != null) ? $dateFinish : date("Y-m-d H:i:s");
|
||||||
|
|
||||||
@@ -432,4 +433,44 @@ class Task
|
|||||||
};
|
};
|
||||||
$this->runTask($job);
|
$this->runTask($job);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This fills the report by process.
|
||||||
|
* @param string $dateInit
|
||||||
|
* @param string $dateFinish
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function fillReportByProcess($dateInit, $dateFinish)
|
||||||
|
{
|
||||||
|
if ($dateInit == null) {
|
||||||
|
if ($this->asynchronous === false) {
|
||||||
|
eprintln("You must enter the starting date.", "red");
|
||||||
|
eprintln('Example: +init-date"YYYY-MM-DD HH:MM:SS" +finish-date"YYYY-MM-DD HH:MM:SS"', "red");
|
||||||
|
}
|
||||||
|
if ($this->asynchronous === true) {
|
||||||
|
$message = 'You must enter the starting date. Example: +init-date"YYYY-MM-DD HH:MM:SS" +finish-date"YYYY-MM-DD HH:MM:SS"';
|
||||||
|
Log::channel('taskScheduler:taskScheduler')->info($message, Bootstrap::context());
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$job = function() {
|
||||||
|
try {
|
||||||
|
|
||||||
|
$dateFinish = ($dateFinish != null) ? $dateFinish : date("Y-m-d H:i:s");
|
||||||
|
$appcv = new AppCacheView();
|
||||||
|
$appcv->setPathToAppCacheFiles(PATH_METHODS . 'setup' . PATH_SEP . 'setupSchemas' . PATH_SEP);
|
||||||
|
|
||||||
|
$this->setExecutionMessage("Calculating data to fill the 'Process Reporting'...");
|
||||||
|
$appcv->fillReportByProcess($dateInit, $dateFinish);
|
||||||
|
$this->setExecutionResultMessage("DONE");
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$this->setExecutionResultMessage("WITH ERRORS", "error");
|
||||||
|
if ($this->asynchronous === false) {
|
||||||
|
eprintln(" '-" . $e->getMessage(), "red");
|
||||||
|
}
|
||||||
|
$this->saveLog("fillReportByProcess", "error", "Error in fill report by process: " . $e->getMessage());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
$this->runTask($job);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user