You are here

public function BatchQueueMongodb::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 QueueMongodb::claimItem

File

src/BatchQueueMongodb.php, line 51
QueueMongodb functionality.

Class

BatchQueueMongodb
MongoDB batch queue implementation.

Namespace

Drupal\mongodb

Code

public function claimItem($lease_time = 30) {
  $this
    ->garbageCollection();
  $result = $this
    ->mongoCollection()
    ->find([
    'expire' => 0,
  ])
    ->limit(1)
    ->sort([
    'created' => 1,
  ]);
  if ($result
    ->hasNext()) {
    $return = (object) $result
      ->getNext();
    $return->data = unserialize($return->data);
    return $return;
  }
  return FALSE;
}