PMCORE-2195 Migrate to queue job - Cron File: sendnotificationscron.php
This commit is contained in:
committed by
Julio Cesar Laura Avendaño
parent
0020d75ca3
commit
5bee4352b5
@@ -396,4 +396,32 @@ class TaskTest extends TestCase
|
||||
Queue::assertPushed(TaskScheduler::class);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This test verify the sendNotifications activity method for synchronous and asynchronous execution.
|
||||
* @test
|
||||
* @covers ProcessMaker\TaskScheduler\Task::runTask()
|
||||
* @covers ProcessMaker\TaskScheduler\Task::sendNotifications()
|
||||
* @dataProvider asynchronousCases
|
||||
*/
|
||||
public function it_should_test_sendNotifications_method($asynchronous)
|
||||
{
|
||||
$task = new Task($asynchronous, '');
|
||||
|
||||
//assert synchronous for cron file
|
||||
if ($asynchronous === false) {
|
||||
ob_start();
|
||||
$task->sendNotifications();
|
||||
$printing = ob_get_clean();
|
||||
$this->assertRegExp("/Resending Notifications/", $printing);
|
||||
}
|
||||
|
||||
//assert asynchronous for job process
|
||||
if ($asynchronous === true) {
|
||||
Queue::fake();
|
||||
Queue::assertNothingPushed();
|
||||
$task->sendNotifications();
|
||||
Queue::assertPushed(TaskScheduler::class);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
* @see workflow/engine/bin/messageeventcron.php
|
||||
* @see workflow/engine/bin/timereventcron.php
|
||||
* @see workflow/engine/bin/ldapcron.php
|
||||
* @see workflow/engine/bin/sendnotificationscron.php
|
||||
* @see workflow/engine/methods/setup/cron.php
|
||||
*
|
||||
* @link https://wiki.processmaker.com/3.2/Executing_cron.php
|
||||
@@ -345,7 +344,10 @@ try {
|
||||
$timerEvent->startContinueCaseByTimerEvent($now, true);
|
||||
break;
|
||||
case 'sendnotificationscron':
|
||||
sendNotifications();
|
||||
if (empty($argvx) || strpos($argvx, "send-notifications") !== false) {
|
||||
$task = new Task($asynchronous, $sObject);
|
||||
$task->sendNotifications();
|
||||
}
|
||||
break;
|
||||
/*----------------------------------********---------------------------------*/
|
||||
case 'actionsByEmailEmailResponse':
|
||||
@@ -645,51 +647,3 @@ function synchronizeGmailLabels()
|
||||
}
|
||||
}
|
||||
/*----------------------------------********---------------------------------*/
|
||||
|
||||
function sendNotifications()
|
||||
{
|
||||
try {
|
||||
global $argvx;
|
||||
if ($argvx != "" && strpos($argvx, "send-notifications") === false) {
|
||||
return false;
|
||||
}
|
||||
setExecutionMessage("Resending Notifications");
|
||||
setExecutionResultMessage("PROCESSING");
|
||||
$notQueue = new \NotificationQueue();
|
||||
$notQueue->checkIfCasesOpenForResendingNotification();
|
||||
$notificationsAndroid = $notQueue->loadStatusDeviceType('pending', 'android');
|
||||
if ($notificationsAndroid) {
|
||||
setExecutionMessage("|-- Send Android's Notifications");
|
||||
$n = 0;
|
||||
foreach ($notificationsAndroid as $key => $item) {
|
||||
$oNotification = new \ProcessMaker\BusinessModel\Light\PushMessageAndroid();
|
||||
$oNotification->setSettingNotification();
|
||||
$oNotification->setDevices(unserialize($item['DEV_UID']));
|
||||
$response['android'] = $oNotification->send($item['NOT_MSG'], unserialize($item['NOT_DATA']));
|
||||
$notQueue = new \NotificationQueue();
|
||||
$notQueue->changeStatusSent($item['NOT_UID']);
|
||||
$n += $oNotification->getNumberDevices();
|
||||
}
|
||||
setExecutionResultMessage("Processed $n");
|
||||
}
|
||||
$notificationsApple = $notQueue->loadStatusDeviceType('pending', 'apple');
|
||||
if ($notificationsApple) {
|
||||
setExecutionMessage("|-- Send Apple Notifications");
|
||||
$n = 0;
|
||||
foreach ($notificationsApple as $key => $item) {
|
||||
$oNotification = new \ProcessMaker\BusinessModel\Light\PushMessageIOS();
|
||||
$oNotification->setSettingNotification();
|
||||
$oNotification->setDevices(unserialize($item['DEV_UID']));
|
||||
$response['apple'] = $oNotification->send($item['NOT_MSG'], unserialize($item['NOT_DATA']));
|
||||
$notQueue = new \NotificationQueue();
|
||||
$notQueue->changeStatusSent($item['NOT_UID']);
|
||||
$n += $oNotification->getNumberDevices();
|
||||
}
|
||||
setExecutionResultMessage("Processed $n");
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
setExecutionResultMessage("WITH ERRORS", "error");
|
||||
eprintln(" '-" . $e->getMessage(), "red");
|
||||
saveLog("ExecuteSendNotifications", "error", "Error when sending notifications " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,9 @@ use Exception;
|
||||
use G;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use ldapadvancedClassCron;
|
||||
use NotificationQueue;
|
||||
use ProcessMaker\BusinessModel\Light\PushMessageAndroid;
|
||||
use ProcessMaker\BusinessModel\Light\PushMessageIOS;
|
||||
use ProcessMaker\Core\JobsManager;
|
||||
use ProcessMaker\Plugins\PluginRegistry;
|
||||
use Propel;
|
||||
@@ -488,4 +491,56 @@ class Task
|
||||
};
|
||||
$this->runTask($job);
|
||||
}
|
||||
|
||||
/**
|
||||
* This execute the sending of notifications.
|
||||
*/
|
||||
function sendNotifications()
|
||||
{
|
||||
$job = function() {
|
||||
try {
|
||||
$this->setExecutionMessage("Resending Notifications");
|
||||
$this->setExecutionResultMessage("PROCESSING");
|
||||
$notQueue = new NotificationQueue();
|
||||
$notQueue->checkIfCasesOpenForResendingNotification();
|
||||
$notificationsAndroid = $notQueue->loadStatusDeviceType('pending', 'android');
|
||||
if ($notificationsAndroid) {
|
||||
$this->setExecutionMessage("|-- Send Android's Notifications");
|
||||
$n = 0;
|
||||
foreach ($notificationsAndroid as $key => $item) {
|
||||
$notification = new PushMessageAndroid();
|
||||
$notification->setSettingNotification();
|
||||
$notification->setDevices(unserialize($item['DEV_UID']));
|
||||
$response['android'] = $notification->send($item['NOT_MSG'], unserialize($item['NOT_DATA']));
|
||||
$notQueue = new NotificationQueue();
|
||||
$notQueue->changeStatusSent($item['NOT_UID']);
|
||||
$n += $notification->getNumberDevices();
|
||||
}
|
||||
$this->setExecutionResultMessage("Processed $n");
|
||||
}
|
||||
$notificationsApple = $notQueue->loadStatusDeviceType('pending', 'apple');
|
||||
if ($notificationsApple) {
|
||||
$this->setExecutionMessage("|-- Send Apple Notifications");
|
||||
$n = 0;
|
||||
foreach ($notificationsApple as $key => $item) {
|
||||
$notification = new PushMessageIOS();
|
||||
$notification->setSettingNotification();
|
||||
$notification->setDevices(unserialize($item['DEV_UID']));
|
||||
$response['apple'] = $notification->send($item['NOT_MSG'], unserialize($item['NOT_DATA']));
|
||||
$notQueue = new NotificationQueue();
|
||||
$notQueue->changeStatusSent($item['NOT_UID']);
|
||||
$n += $notification->getNumberDevices();
|
||||
}
|
||||
$this->setExecutionResultMessage("Processed $n");
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$this->setExecutionResultMessage("WITH ERRORS", "error");
|
||||
if ($this->asynchronous === false) {
|
||||
eprintln(" '-" . $e->getMessage(), "red");
|
||||
}
|
||||
$this->saveLog("ExecuteSendNotifications", "error", "Error when sending notifications " . $e->getMessage());
|
||||
}
|
||||
};
|
||||
$this->runTask($job);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user