Advanced Queue

Provides a better Queue API for Drupal with job states, retries, delayed processing, and Views-powered job listings.

advancedqueue
5,654 sites
66
drupal.org

インストール

Drupal 11, 10 v8.x-1.5
composer require 'drupal/advancedqueue:8.x-1.5'
Drupal 9 v8.x-1.3
composer require 'drupal/advancedqueue:8.x-1.3'

概要

Advanced Queueは、DrupalコアのQueue APIと比較して改良されたキューAPIを提供します。プラグイン可能なバックエンドストレージを持つ設定エンティティ(Queue)と、ジョブタイプを定義するためのプラグインシステムを導入しています。

各ジョブは定義された状態(queued、processing、success、failure)を経て処理され、処理後に結果(状態、メッセージ、処理時間)を保存します。このモジュールは、設定可能な遅延を伴う自動リトライ、遅延/スケジュールされたジョブ実行、一括ジョブ作成、重複ジョブ検出をサポートしています。

Queueはcron経由またはデーモン(Drushコマンド)経由で処理できます。このモジュールは、削除、リトライ、解放などの一括操作を含む、ジョブの監視と管理のためのViews統合を備えた包括的な管理UIを提供します。

Features

  • 4つの状態によるジョブ状態追跡:queued、processing、success、failure
  • 状態、メッセージ、処理時間を含むジョブ結果の保存
  • カスタマイズ可能なリトライ遅延を伴う、ジョブタイプごとの設定可能なリトライ
  • 遅延/スケジュールされたジョブ処理 - 将来実行するジョブをスケジュール可能
  • キューストレージ用のプラグイン可能なバックエンドシステム(データベースバックエンド付属)
  • カスタムジョブプロセッサを定義するためのプラグイン可能なジョブタイプシステム
  • フィンガープリントによる重複ジョブの検出と処理
  • 効率的なエンキュー用の一括ジョブ作成API
  • シグナルハンドリング(SIGTERM/SIGINT)を備えたcronまたはDrushデーモンコマンドによる処理
  • フィルタリング、ソート、一括操作を備えたViewsによるジョブ一覧
  • 件数または日数のしきい値に基づく完了ジョブの自動クリーンアップ
  • Queue設定エンティティを作成・管理するための管理UI

Use Cases

Background Email Processing

Create a job type plugin for sending emails. When an email needs to be sent, create a Job with the email data as payload and enqueue it. The job processor will send emails in the background, with automatic retries if SMTP fails.

Scheduled Content Publishing

Create jobs with a future availability time to schedule content operations. Use the delay parameter when enqueueing to set when the job should be processed.

High-Volume Data Processing

Use bulk job creation (enqueueJobs) to efficiently queue thousands of items for processing. Configure daemon processing with unlimited time for continuous processing.

Subscription Renewals

Similar to Commerce Recurring, create a job type for recurring operations. Configure retries with delays to handle temporary payment failures gracefully.

Import/Export Operations

Queue large import or export operations as background jobs. Use the processing time limit to prevent timeouts and allow processing across multiple cron runs.

API Rate-Limited Operations

Queue operations that call rate-limited external APIs. Configure retry delays to respect rate limits when operations fail due to throttling.

Tips

  • Use different queues to separate jobs by priority, processing method, or backend storage
  • Set appropriate lease_time based on your longest-running job to prevent premature release
  • Use daemon processing for time-critical jobs that shouldn't wait for cron
  • Configure cleanup thresholds to prevent database bloat from completed jobs
  • Implement the handleDuplicateJobs() method in your job type to customize duplicate handling (merge, replace, discard)
  • Use the POST_PROCESS event to send notifications or trigger follow-up actions after job completion
  • For production sites, consider running multiple Drush daemon processes for parallel processing

Technical Details

Admin Pages 4
Queues /admin/config/system/queues

Main administration page listing all queue configuration entities. Displays each queue with its label, job counts by state (Queued, Processing, Success, Failure), and operations links (Edit, Delete, List jobs). Provides an overview of all queues and their current job statistics.

Add queue /admin/config/system/queues/add

Form for creating a new queue configuration entity with backend selection and processing options.

Edit queue /admin/config/system/queues/manage/{queue_id}

Form for editing an existing queue configuration. Backend cannot be changed after creation.

Jobs /admin/config/system/queues/{queue_id}/jobs

Views-powered listing of all jobs in a specific queue. Displays job details including ID, retry count, state (with icon), type, payload (JSON), available date, processed date, message, and operations. Supports filtering by state and job type, sorting, pagination (50 items per page), and bulk operations.

権限 1
Administer queues

Allows users to create, edit, delete queues and manage jobs. This is a restricted access permission that should only be granted to trusted administrators.

Hooks 2
hook_advancedqueue_backend_info_alter

Allows modules to alter backend plugin definitions

hook_advancedqueue_job_type_info_alter

Allows modules to alter job type plugin definitions

Drush Commands 2
advancedqueue:queue:process <queue_id>

Process jobs from a specific queue. The command will process jobs until the timeout is reached or the queue is empty (if stop_when_empty is enabled). Supports graceful shutdown via SIGTERM and SIGINT signals.

advancedqueue:queue:list

List all configured queues with their job counts by state.

Troubleshooting 4
Jobs stuck in 'processing' state

This occurs when a worker crashes or times out. Jobs will automatically be released after the lease time expires (default 300 seconds). You can also manually release jobs via the admin UI or bulk operations.

Queue not processing during cron

Verify the queue's processor is set to 'Cron' (not Daemon). Check that cron is running and the processing_time is appropriate for your cron interval.

Duplicate jobs being created

Ensure your job type plugin has allow_duplicates set to FALSE. The backend must implement SupportsDetectingDuplicateJobsInterface (Database backend does). Override createJobFingerprint() in your job type if the default fingerprint logic doesn't suit your needs.

Jobs failing immediately without retry

Retries only occur when the job type's process() method returns JobResult::failure(). Exceptions during processing cause immediate failure without retry. Configure max_retries in your job type plugin annotation/attribute.

Security Notes 3
  • The 'administer advancedqueue' permission is marked as restricted access and should only be granted to trusted administrators
  • Job payloads are stored as JSON blobs - avoid storing sensitive data directly in payloads
  • Validate and sanitize any data in job payloads before processing to prevent injection attacks