You are here

public function QueueMongodb::claimItem in MongoDB 8

Claim an item in the queue for processing.

Parameters

string $lease_time: How long the processing is expected to take in seconds,

Return value

object/boolean On success we return an item object. If the queue is unable to claim an item it returns false.

Overrides QueueInterface::claimItem

1 method overrides QueueMongodb::claimItem()
BatchQueueMongodb::claimItem in src/BatchQueueMongodb.php
Claim an item in the queue for processing.

File

src/QueueMongodb.php, line 83
Contains \Drupal\mongodb\QueueMongodb

Class

QueueMongodb
MongoDB queue implementation.

Namespace

Drupal\mongodb

Code

public function claimItem($lease_time = 30) {
  $this
    ->garbageCollection();
  $result = $this
    ->mongoCollection()
    ->findAndModify(array(
    'expire' => 0,
  ), array(
    '$set' => array(
      'expire' => time() + $lease_time,
    ),
  ), array(), array(
    'sort' => array(
      'created' => 1,
    ),
  ));
  if (!$result) {
    return FALSE;
  }
  $result['data'] = unserialize($result['data']);
  return empty($result) ? FALSE : (object) $result;
}