Verified Commit 889dc157 authored by Alex Pott's avatar Alex Pott
Browse files

Revert "Issue #3230541 by cliddell, jday, yogeshmpawar, neclimdul, cmlara,...

Revert "Issue #3230541 by cliddell, jday, yogeshmpawar, neclimdul, cmlara, Charlie ChX Negyesi: Queue items only reserved by cron for 1 second"

This reverts commit d218a382.
parent d218a382
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -52,15 +52,13 @@ class QueueWorker extends Plugin {
  public $title;

  /**
   * An associative array containing optional keys.
   * An associative array containing an optional key.
   *
   * This property is optional and it does not need to be declared.
   *
   * Available keys:
   * - time (optional): How much time Drupal cron should spend on calling this
   *   worker in seconds. Defaults to 15.
   * - lease_time: (optional) How long the lease is for a queue item when
   *   called from cron in seconds. Defaults to 30.
   *
   * @var array
   */
+3 −3
Original line number Diff line number Diff line
@@ -174,10 +174,10 @@ protected function processQueues() {
        $this->queueFactory->get($queue_name)->createQueue();

        $queue_worker = $this->queueManager->createInstance($queue_name);
        $end = $this->time->getCurrentTime() + $info['cron']['time'] ?? static::DEFAULT_QUEUE_CRON_TIME;
        $end = time() + ($info['cron']['time'] ?? 15);
        $queue = $this->queueFactory->get($queue_name);
        $lease_time = $info['cron']['lease_time'] ?? static::DEFAULT_QUEUE_CRON_LEASE_TIME;
        while ($this->time->getCurrentTime() < $end && ($item = $queue->claimItem($lease_time))) {
        $lease_time = isset($info['cron']['time']) ?: NULL;
        while (time() < $end && ($item = $queue->claimItem($lease_time))) {
          try {
            $queue_worker->processItem($item->data);
            $queue->deleteItem($item);
+0 −10
Original line number Diff line number Diff line
@@ -9,16 +9,6 @@
 */
interface CronInterface {

  /**
   * The default time cron should execute each queue in seconds.
   */
  public const DEFAULT_QUEUE_CRON_TIME = 15;

  /**
   * The default lease time a queue item should get when called from cron.
   */
  public const DEFAULT_QUEUE_CRON_LEASE_TIME = 30;

  /**
   * Executes a cron run.
   *
+2 −2
Original line number Diff line number Diff line
@@ -241,7 +241,7 @@ public function garbageCollection() {
    try {
      // Clean up the queue for failed batches.
      $this->connection->delete(static::TABLE_NAME)
        ->condition('created', \Drupal::time()->getRequestTime() - 864000, '<')
        ->condition('created', REQUEST_TIME - 864000, '<')
        ->condition('name', 'drupal_batch:%', 'LIKE')
        ->execute();

@@ -252,7 +252,7 @@ public function garbageCollection() {
          'expire' => 0,
        ])
        ->condition('expire', 0, '<>')
        ->condition('expire', \Drupal::time()->getRequestTime(), '<')
        ->condition('expire', REQUEST_TIME, '<')
        ->execute();
    }
    catch (\Exception $e) {
+14 −0
Original line number Diff line number Diff line
@@ -34,6 +34,20 @@ public function __construct(\Traversable $namespaces, CacheBackendInterface $cac
    $this->alterInfo('queue_info');
  }

  /**
   * {@inheritdoc}
   */
  public function processDefinition(&$definition, $plugin_id) {
    parent::processDefinition($definition, $plugin_id);

    // Assign a default time if a cron is specified.
    if (isset($definition['cron'])) {
      $definition['cron'] += [
        'time' => 15,
      ];
    }
  }

  /**
   * {@inheritdoc}
   *
Loading