PMCORE-2181 Migrate to queue job - Cron File: cron.php - Activity: calculate

This commit is contained in:
Roly Rudy Gutierrez Pinto
2020-09-24 09:09:16 -04:00
committed by Julio Cesar Laura Avendaño
parent ef68bf318b
commit 7f6d4dc4b4
3 changed files with 55 additions and 24 deletions

View File

@@ -166,4 +166,32 @@ class TaskTest extends TestCase
Queue::assertPushed(TaskScheduler::class); Queue::assertPushed(TaskScheduler::class);
} }
} }
/**
* This test verify the calculateDuration activity method for synchronous and asynchronous execution.
* @test
* @covers ProcessMaker\TaskScheduler\Task::runTask()
* @covers ProcessMaker\TaskScheduler\Task::calculateDuration()
* @dataProvider asynchronousCases
*/
public function it_should_test_calculateDuration_method($asynchronous)
{
$task = new Task($asynchronous, '');
//assert synchronous for cron file
if ($asynchronous === false) {
ob_start();
$task->calculateDuration();
$printing = ob_get_clean();
$this->assertRegExp("/DONE/", $printing);
}
//assert asynchronous for job process
if ($asynchronous === true) {
Queue::fake();
Queue::assertNothingPushed();
$task->calculateDuration();
Queue::assertPushed(TaskScheduler::class);
}
}
} }

View File

@@ -297,7 +297,9 @@ try {
if (empty($argvx) || strpos($argvx, "unpause") !== false) { if (empty($argvx) || strpos($argvx, "unpause") !== false) {
$task->unpauseApplications($now); $task->unpauseApplications($now);
} }
calculateDuration(); if (empty($argvx) || strpos($argvx, "calculate") !== false) {
$task->calculateDuration();
}
/*----------------------------------********---------------------------------*/ /*----------------------------------********---------------------------------*/
calculateAppDuration(); calculateAppDuration();
/*----------------------------------********---------------------------------*/ /*----------------------------------********---------------------------------*/
@@ -438,28 +440,6 @@ function executeCustomCronFunction($pathFile, $className)
} }
} }
function calculateDuration()
{
global $argvx;
if ($argvx != "" && strpos($argvx, "calculate") === false) {
return false;
}
setExecutionMessage("Calculating Duration");
try {
$oAppDelegation = new AppDelegation();
$oAppDelegation->calculateDuration(1);
setExecutionResultMessage('DONE');
saveLog('calculateDuration', 'action', 'Calculating Duration');
} catch (Exception $oError) {
setExecutionResultMessage('WITH ERRORS', 'error');
eprintln(" '-" . $oError->getMessage(), 'red');
saveLog('calculateDuration', 'error', 'Error Calculating Duration: ' . $oError->getMessage());
}
}
/*----------------------------------********---------------------------------*/ /*----------------------------------********---------------------------------*/
function calculateAppDuration() function calculateAppDuration()

View File

@@ -2,8 +2,10 @@
namespace ProcessMaker\TaskScheduler; namespace ProcessMaker\TaskScheduler;
use AppDelegation;
use App\Jobs\TaskScheduler; use App\Jobs\TaskScheduler;
use Bootstrap; use Bootstrap;
use Cases;
use ConfigurationPeer; use ConfigurationPeer;
use Criteria; use Criteria;
use Exception; use Exception;
@@ -192,7 +194,7 @@ class Task
$job = function() use($now) { $job = function() use($now) {
$this->setExecutionMessage("Unpausing applications"); $this->setExecutionMessage("Unpausing applications");
try { try {
$cases = new \Cases(); $cases = new Cases();
$cases->ThrowUnpauseDaemon($now, 1); $cases->ThrowUnpauseDaemon($now, 1);
$this->setExecutionResultMessage('DONE'); $this->setExecutionResultMessage('DONE');
@@ -205,4 +207,25 @@ class Task
}; };
$this->runTask($job); $this->runTask($job);
} }
/**
* This calculate duration.
*/
public function calculateDuration()
{
$job = function() {
$this->setExecutionMessage("Calculating Duration");
try {
$appDelegation = new AppDelegation();
$appDelegation->calculateDuration(1);
$this->setExecutionResultMessage('DONE');
$this->saveLog('calculateDuration', 'action', 'Calculating Duration');
} catch (Exception $e) {
$this->setExecutionResultMessage('WITH ERRORS', 'error');
eprintln(" '-" . $e->getMessage(), 'red');
$this->saveLog('calculateDuration', 'error', 'Error Calculating Duration: ' . $e->getMessage());
}
};
$this->runTask($job);
}
} }