Skip to content

Commit

Permalink
MAE-318: Handle edge case when the job executed twice
Browse files Browse the repository at this point in the history
If the job executed during the execution of the queue, there will be
repeated tasks in the queue and this commit fix it and only adds tasks
when the queue is empty.
  • Loading branch information
ahed-compucorp committed Feb 15, 2021
1 parent 8824a1e commit 5c26873
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion CRM/MembershipExtras/Job/OfflineAutoRenewal.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@ class CRM_MembershipExtras_Job_OfflineAutoRenewal {

private $queue;

/**
* @var int
*/
private $numberOfQueueItems;

public function __construct() {
$this->queue = OfflineAutoRenewalQueue::getQueue();
$this->numberOfQueueItems= (int) $this->queue->numberOfItems();
}

/**
Expand All @@ -19,7 +25,9 @@ public function __construct() {
* @return True
*/
public function run() {
$this->addTasksToQueue();
if ($this->numberOfQueueItems === 0 ) {
$this->addTasksToQueue();
}
$this->runQueue();

return TRUE;
Expand Down

0 comments on commit 5c26873

Please sign in to comment.