PMCORE-2180 Migrate to queue job - Cron File: cron.php - Activity: unpause

This commit is contained in:
Roly Rudy Gutierrez Pinto
2020-09-24 08:25:51 -04:00
committed by Julio Cesar Laura Avendaño
parent ca82c81399
commit ef68bf318b
3 changed files with 54 additions and 25 deletions

View File

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

View File

@@ -294,7 +294,9 @@ try {
if (empty($argvx) || strpos($argvx, "emails") !== false) {
$task->resendEmails($now, $dateSystem);
}
unpauseApplications();
if (empty($argvx) || strpos($argvx, "unpause") !== false) {
$task->unpauseApplications($now);
}
calculateDuration();
/*----------------------------------********---------------------------------*/
calculateAppDuration();
@@ -361,30 +363,6 @@ try {
G::outRes(G::LoadTranslation("ID_EXCEPTION_LOG_INTERFAZ", array($token)) . "\n");
}
function unpauseApplications()
{
global $argvx;
global $now;
if ($argvx != "" && strpos($argvx, "unpause") === false) {
return false;
}
setExecutionMessage("Unpausing applications");
try {
$oCases = new Cases();
$oCases->ThrowUnpauseDaemon($now, 1);
setExecutionResultMessage('DONE');
saveLog('unpauseApplications', 'action', 'Unpausing Applications');
} catch (Exception $oError) {
setExecutionResultMessage('WITH ERRORS', 'error');
eprintln(" '-" . $oError->getMessage(), 'red');
saveLog('unpauseApplications', 'error', 'Error Unpausing Applications: ' . $oError->getMessage());
}
}
function executePlugins()
{
global $argvx;

View File

@@ -182,4 +182,27 @@ class Task
};
$this->runTask($job);
}
/**
* This unpause applications.
* @param string $now
*/
public function unpauseApplications($now)
{
$job = function() use($now) {
$this->setExecutionMessage("Unpausing applications");
try {
$cases = new \Cases();
$cases->ThrowUnpauseDaemon($now, 1);
$this->setExecutionResultMessage('DONE');
$this->saveLog('unpauseApplications', 'action', 'Unpausing Applications');
} catch (Exception $e) {
$this->setExecutionResultMessage('WITH ERRORS', 'error');
eprintln(" '-" . $e->getMessage(), 'red');
$this->saveLog('unpauseApplications', 'error', 'Error Unpausing Applications: ' . $e->getMessage());
}
};
$this->runTask($job);
}
}