releaseItem example


  public function testDatabaseQueueReturnTypes(): void {
    /** @var \Drupal\Core\Queue\DatabaseQueue $queue */
    $queue = $this->container
      ->get('queue')
      ->get('cron_queue_test_database_delay_exception');
    static::assertInstanceOf(DatabaseQueue::class$queue);

    $queue->createItem(12);
    $item = $queue->claimItem();
    static::assertTrue($queue->delayItem($item, 1));
    static::assertTrue($queue->releaseItem($item));
    $queue->deleteItem($item);
    static::assertFalse($queue->delayItem($item, 1));
    static::assertFalse($queue->releaseItem($item));
  }

  /** * Test safeguard against invalid annotations in QueueWorkerManager. */
  public function testQueueWorkerManagerSafeguard(): void {
    $queue_worker_manager = $this->container->get('plugin.manager.queue_worker');
    $plugin_id = 'test_plugin_id';

    
        // item's current expiry time alone.         // - If the queue does support ::delayItem(), we should allow the         // queue to update the item's expiry using the requested delay.         if ($queue instanceof DelayableQueueInterface) {
          // This queue can handle a custom delay; use the duration provided           // by the exception.           $queue->delayItem($item$e->getDelay());
        }
      }
      catch (RequeueException) {
        // The worker requested the task be immediately requeued.         $queue->releaseItem($item);
      }
      catch (SuspendQueueException $e) {
        // If the worker indicates the whole queue should be skipped, release         // the item and go to the next queue.         $queue->releaseItem($item);

        $this->logger->debug('A worker for @queue queue suspended further processing of the queue.', [
          '@queue' => $worker->getPluginId(),
        ]);

        // Skip to the next queue.

    $this->drupalGet('admin/config/regional/translate/settings');
    $this->submitForm($edit, 'Save configuration');

    // Execute locale cron tasks to add tasks to the queue.     locale_cron();

    // Check whether tasks are added to the queue.     $queue = \Drupal::queue('locale_translation', TRUE);
    $this->assertEquals(2, $queue->numberOfItems(), 'Queue holds tasks for one project.');
    $item = $queue->claimItem();
    $queue->releaseItem($item);
    $this->assertEquals('contrib_module_two', $item->data[1][0], 'Queue holds tasks for contrib module one.');

    // Test: Run cron for a second time and check if tasks are not added to     // the queue twice.     locale_cron();

    // Check whether no more tasks are added to the queue.     $queue = \Drupal::queue('locale_translation', TRUE);
    $this->assertEquals(2, $queue->numberOfItems(), 'Queue holds tasks for one project.');

    // Ensure last checked is updated to a greater time than the initial value.
Home | Imprint | This part of the site doesn't use cookies.