VOOZH about

URL: https://deepwiki.com/hypervel/queue/6.5-queue-maintenance-commands

⇱ Queue Maintenance Commands | hypervel/queue | DeepWiki


Loading...
Menu

Queue Maintenance Commands

This document covers commands for maintaining queue health and operational continuity. These commands handle worker lifecycle management, queue data cleanup, and batch job operations.

For active job processing commands, see Work Command and Listen Command. For failed job management, see Failed Job Management Commands. For queue monitoring, see Monitor Command.

Overview

The Hypervel Queue package provides three categories of maintenance commands:

CommandClassPurpose
queue:restartRestartCommandSignal all running workers to gracefully restart
queue:clearClearCommandRemove all jobs from a queue
queue:retry-batchRetryBatchCommandRetry all jobs in a failed batch
queue:prune-batchesPruneeBatchesCommandRemove old batch records from storage

These commands are registered in ConfigProvider.php40-53 and provide essential operational capabilities for production queue management.

Sources: src/ConfigProvider.php

Command Registration and Dependencies


Sources: src/ConfigProvider.php, publish/queue.php

Restart Command

Purpose

The queue:restart command signals all running queue workers to gracefully terminate after completing their current job. This enables zero-downtime deployments by allowing workers to reload updated code without interrupting job processing.

Command Syntax


Signal Mechanism

The restart command operates by writing a restart signal to a shared storage backend (typically Redis or cache). Workers continuously check for this signal during their daemon loop referenced in Worker System.


Worker Detection

Workers detect the restart signal by comparing their startup timestamp with the restart signal timestamp. When the signal timestamp is newer than the worker's startup time, the worker terminates gracefully. See Worker Class for details on the daemon loop and exit conditions.

Use Cases

ScenarioUsage
Code DeploymentRestart workers to load new application code
Configuration ChangesApply updated queue configuration without manual process killing
Memory Leak RecoveryScheduled restarts to prevent memory accumulation
Maintenance WindowsCoordinated worker restart before maintenance operations

Sources: src/Console/RestartCommand.php (inferred), src/ConfigProvider.php

Clear Command

Purpose

The queue:clear command removes all jobs from a specified queue. This is useful for emergency queue draining, clearing stuck jobs, or resetting development environments.

Command Syntax


Arguments and Options

ParameterTypeDescription
connectionArgumentQueue connection name (default from config)
--queueOptionQueue name to clear (default: 'default')

Driver Support

The clear operation is only supported by queue drivers that implement the ClearableQueue interface. Currently supported drivers:


Behavior

For Redis-based queues, the clear operation removes jobs from:

  • Pending jobs list (queues:{queue})
  • Delayed jobs sorted set (queues:{queue}:delayed)
  • Reserved jobs sorted set (queues:{queue}:reserved)

For SQS queues, the clear operation uses the AWS PurgeQueue API to delete all messages.

Warning

The clear operation is irreversible. Jobs cannot be recovered after clearing. For production systems, consider:

  • Moving jobs to a backup queue first
  • Using the failed job system to handle problematic jobs
  • Implementing job archival before clearing

Sources: src/Console/ClearCommand.php (inferred), src/Contracts/ClearableQueue.php (inferred), publish/queue.php

Batch Management Commands

Job batching allows multiple jobs to be grouped together and tracked as a unit. Batch management commands handle retry and cleanup operations for batch jobs.

Configuration

Batch operations require database configuration in queue.php120-123:


The job_batches table stores batch metadata including:

  • Batch ID (UUID)
  • Batch name
  • Total jobs count
  • Pending jobs count
  • Failed jobs count
  • Timestamps and options

Sources: publish/queue.php

Retry Batch Command

Purpose

The queue:retry-batch command retries all failed jobs within a specific batch. This is useful when a batch partially fails due to temporary issues like network errors or rate limits.

Command Syntax


Processing Flow


Batch State Updates

When retrying batch jobs, the command updates batch counters:

CounterChange
failed_jobsDecremented for each retried job
pending_jobsIncremented for each retried job
failed_job_idsFailed job IDs removed from list

Sources: src/Console/RetryBatchCommand.php (inferred), publish/queue.php

Prune Batches Command

Purpose

The queue:prune-batches command removes old batch records from the database. Batches accumulate over time and can bloat the database if not regularly cleaned.

Command Syntax


Options

OptionTypeDefaultDescription
--hoursInteger24Age threshold in hours
--unfinishedInteger0Include unfinished batches (0 or 1)
--cancelledBooleanfalseOnly prune cancelled batches

Pruning Logic


Recommended Schedule

For production environments, schedule regular batch pruning:


This prevents unbounded growth of the job_batches table while retaining sufficient history for debugging.

Sources: src/Console/PruneBatchesCommand.php (inferred), publish/queue.php

Command Dependencies and Integration

Dependency Injection

All maintenance commands receive dependencies through the DI container:


The QueueManager is resolved through the FactoryContract interface registered in ConfigProvider.php34 ensuring commands receive a fully configured manager instance with exception handling setup from QueueManagerFactory.php14-33

Configuration Dependencies

Commands read configuration from queue.php:

CommandConfiguration SectionUsage
RestartCommandN/ACache key prefix only
ClearCommandconnectionsConnection and queue selection
RetryBatchCommandbatchingDatabase connection and table
PruneBatchesCommandbatchingDatabase connection and table

Sources: src/ConfigProvider.php, src/QueueManagerFactory.php, publish/queue.php

Error Handling and Edge Cases

RestartCommand

ScenarioBehavior
Cache unavailableCommand fails with connection error
No workers runningSignal written but no effect until workers start
Multiple executionsLast signal timestamp wins

ClearCommand

ScenarioBehavior
Non-clearable driverError: "Queue does not support clearing"
Connection not foundInvalidArgumentException from QueueManager
Empty queueSuccess with zero jobs cleared

RetryBatchCommand

ScenarioBehavior
Batch not foundError: "Unable to find batch"
No failed jobsInfo message, no retries performed
Database unavailableConnection exception

PruneBatchesCommand

ScenarioBehavior
No batches to pruneSuccess with zero deletions
Invalid --hours valueValidation error
Database lockedWait or timeout based on driver

Sources: src/Console/* (inferred)

Integration with Worker Lifecycle

The maintenance commands integrate with the worker system documented in Worker System:


Workers check for the restart signal during their daemon loop between jobs, ensuring they complete in-progress work before terminating. The clear command operates independently and can be executed while workers are running, though cleared jobs will not be processed.

Sources: src/Worker.php (referenced), src/Console/RestartCommand.php (inferred), src/Console/ClearCommand.php (inferred)