public function Database::enqueueJobs in Advanced Queue 8
Enqueues the given jobs.
Each job will be modified with the assigned queue ID, job ID, and relevant timestamps.
Parameters
\Drupal\advancedqueue\Job[] $jobs: The jobs.
int $delay: The time, in seconds, after which the jobs will become available to consumers. Defaults to 0, indicating no delay.
Overrides BackendInterface::enqueueJobs
1 call to Database::enqueueJobs()
- Database::enqueueJob in src/
Plugin/ AdvancedQueue/ Backend/ Database.php - Enqueues the given job.
File
- src/
Plugin/ AdvancedQueue/ Backend/ Database.php, line 122
Class
- Database
- Provides the database queue backend.
Namespace
Drupal\advancedqueue\Plugin\AdvancedQueue\BackendCode
public function enqueueJobs(array $jobs, $delay = 0) {
if (count($jobs) > 1) {
// Make the inserts atomic, and improve performance on certain engines.
$this->connection
->startTransaction();
}
/** @var \Drupal\advancedqueue\Job $job */
foreach ($jobs as $job) {
$job
->setQueueId($this->queueId);
$job
->setState(Job::STATE_QUEUED);
if (!$job
->getAvailableTime()) {
$job
->setAvailableTime($this->time
->getCurrentTime() + $delay);
}
$fields = $job
->toArray();
unset($fields['id']);
$fields['payload'] = json_encode($fields['payload']);
// InsertQuery supports inserting multiple rows at once, which is faster,
// but that doesn't give us the inserted job IDs.
$query = $this->connection
->insert('advancedqueue')
->fields($fields);
$job_id = $query
->execute();
$job
->setId($job_id);
}
}