public function queue(): void {
$dataSource = $this->getDataSourceObject();
$totalRowCount = $totalRows = $dataSource->getRowCount(['new']);
- $queue = Civi::queue('user_job_' . $this->getUserJobID(), ['type' => 'Sql', 'error' => 'abort', 'runner' => 'task', 'user_job_id' => $this->getUserJobID()]);
+ // The retry limit for the queue is set to 5 - allowing for a few deadlocks but we might consider
+ // making this configurable at some point.
+ $queue = Civi::queue('user_job_' . $this->getUserJobID(), ['type' => 'Sql', 'error' => 'abort', 'runner' => 'task', 'user_job_id' => $this->getUserJobID(), 'retry_limit' => 5]);
UserJob::update(FALSE)->setValues(['queue_id.name' => 'user_job_' . $this->getUserJobID()])->addWhere('id', '=', $this->getUserJobID())->execute();
$offset = 0;
$batchSize = 50;
['userJobID' => $this->getUserJobID(), 'limit' => $batchSize, 'offset' => 0],
ts('Processed %1 rows out of %2', [1 => $offset + $batchSize, 2 => $totalRowCount])
);
+ $task->runAs = ['contactId' => CRM_Core_Session::getLoggedInContactID(), 'domainId' => CRM_Core_Config::domainID()];
$queue->createItem($task);
$totalRows -= $batchSize;
$offset += $batchSize;
*/
protected $entity = 'Contribution';
+ /**
+ * Original value for background processing.
+ *
+ * @var bool
+ */
+ protected $enableBackgroundQueueOriginalValue;
+
/**
* These extensions are inactive at the start. They may be activated during the test. They should be deactivated at the end.
*
protected function setUp(): void {
parent::setUp();
- $origExtensions = array_column(CRM_Extension_System::singleton()->getMapper()->getActiveModuleFiles(), 'fullName');
- $this->assertEquals([], array_intersect($origExtensions, $this->toggleExts), 'These extensions may be enabled and disabled during the test. The start-state and end-state should be the same. It appears that we have an unexpected start-state. Perhaps another test left us with a weird start-state?');
+ $originalExtensions = array_column(CRM_Extension_System::singleton()->getMapper()->getActiveModuleFiles(), 'fullName');
+ $this->assertEquals([], array_intersect($originalExtensions, $this->toggleExts), 'These extensions may be enabled and disabled during the test. The start-state and end-state should be the same. It appears that we have an unexpected start-state. Perhaps another test left us with a weird start-state?');
+ $this->enableBackgroundQueueOriginalValue = Civi::settings()->get('enableBackgroundQueue');
}
/**
CRM_Extension_System::singleton()->getManager()->disable([$ext]);
CRM_Extension_System::singleton()->getManager()->uninstall([$ext]);
}
+ Civi::settings()->set('enableBackgroundQueue', $this->enableBackgroundQueueOriginalValue);
parent::tearDown();
}
* These features are
* - default_value for each field.
*
+ * @dataProvider getBooleanDataProvider
+ *
+ * @param bool $isBackGroundProcessing
+ *
* @throws \CRM_Core_Exception
*/
- public function testImportFromUserJobConfiguration(): void {
+ public function testImportFromUserJobConfiguration(bool $isBackGroundProcessing): void {
+ Civi::settings()->set('enableBackgroundQueue', $isBackGroundProcessing);
+ $this->createLoggedInUser();
$importMappings = [
['name' => 'organization_name'],
['name' => 'legal_name'],
catch (CRM_Core_Exception_PrematureExitException $e) {
$queue = Civi::queue('user_job_' . $this->userJobID);
$this->assertEquals(1, CRM_Core_DAO::singleValueQuery('SELECT COUNT(*) FROM civicrm_queue_item'));
+ $item = $queue->claimItem(0);
+ $this->assertEquals(['contactId' => CRM_Core_Session::getLoggedInContactID(), 'domainId' => CRM_Core_Config::domainID()], $item->data->runAs);
+ $queue->releaseItem($item);
$runner = new CRM_Queue_Runner([
'queue' => $queue,
'errorMode' => CRM_Queue_Runner::ERROR_ABORT,