PMCORE-2181 Migrate to queue job - Cron File: cron.php - Activity: calculate
This commit is contained in:
committed by
Julio Cesar Laura Avendaño
parent
ef68bf318b
commit
7f6d4dc4b4
@@ -166,4 +166,32 @@ class TaskTest extends TestCase
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -297,7 +297,9 @@ try {
|
||||
if (empty($argvx) || strpos($argvx, "unpause") !== false) {
|
||||
$task->unpauseApplications($now);
|
||||
}
|
||||
calculateDuration();
|
||||
if (empty($argvx) || strpos($argvx, "calculate") !== false) {
|
||||
$task->calculateDuration();
|
||||
}
|
||||
/*----------------------------------********---------------------------------*/
|
||||
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()
|
||||
|
||||
@@ -2,8 +2,10 @@
|
||||
|
||||
namespace ProcessMaker\TaskScheduler;
|
||||
|
||||
use AppDelegation;
|
||||
use App\Jobs\TaskScheduler;
|
||||
use Bootstrap;
|
||||
use Cases;
|
||||
use ConfigurationPeer;
|
||||
use Criteria;
|
||||
use Exception;
|
||||
@@ -192,7 +194,7 @@ class Task
|
||||
$job = function() use($now) {
|
||||
$this->setExecutionMessage("Unpausing applications");
|
||||
try {
|
||||
$cases = new \Cases();
|
||||
$cases = new Cases();
|
||||
$cases->ThrowUnpauseDaemon($now, 1);
|
||||
|
||||
$this->setExecutionResultMessage('DONE');
|
||||
@@ -205,4 +207,25 @@ class Task
|
||||
};
|
||||
$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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user