VOOZH about

URL: https://deepwiki.com/hypervel/support/6.4-queue-operations

⇱ Queue Operations | hypervel/support | DeepWiki


Loading...
Menu

Queue Operations

The Queue system provides an interface for asynchronous job processing across multiple queue backends. This page documents the Queue facade and its underlying QueueManager and Queue implementations for pushing jobs, managing connections, inspecting queue state, and extending with custom drivers.

For event dispatching and listeners, see Event System. For testing queue operations with QueueFake, see Queue Testing. For Redis-specific operations that may underlie queue storage, see Redis Operations.

Queue System Architecture

The Queue system follows the Manager pattern to support multiple queue drivers and connections. Jobs are pushed to queues for asynchronous processing by workers.


Sources: src/Facades/Queue.php1-114

Facade Accessor and Core Methods

The Queue facade resolves to Hypervel\Queue\Contracts\Factory, which is typically implemented by QueueManager. The facade provides static access to all queue operations.

Method CategoryKey MethodsDescription
Job Pushingpush(), pushOn(), pushRaw()Dispatch jobs to queues
Delayed Jobslater(), laterOn()Schedule jobs for future execution
Bulk Operationsbulk()Push multiple jobs at once
Job Retrievalpop()Retrieve next job from queue
Queue Inspectionsize(), pendingSize(), delayedSize()Monitor queue state
Connectionsconnection(), connected()Manage queue connections
ConfigurationgetDefaultDriver(), setDefaultDriver()Configure driver selection
Extensionextend(), addConnector()Register custom drivers
Testingfake(), assertPushed()Test doubles and assertions

Sources: src/Facades/Queue.php14-72

Connection Management

The Queue system supports multiple named queue connections, each potentially using different drivers (Redis, Database, SQS, etc.).

Accessing Queue Connections


Connection Methods

MethodReturn TypeDescription
Queue::connection(?string $name)Queue\Contracts\QueueGet a specific queue connection
Queue::connected(?string $name)boolCheck if connection exists
Queue::getDefaultDriver()stringGet the default driver name
Queue::setDefaultDriver(string $name)voidSet the default driver
Queue::getName(?string $connection)stringGet the queue name for a connection

Sources: src/Facades/Queue.php21-27

Default vs Named Connections

When no connection name is specified, methods use the default driver configured in the queue manager. Named connections allow routing different job types to different backends:


Sources: src/Facades/Queue.php22-26

Pushing Jobs to Queues

The Queue facade provides multiple methods for dispatching jobs to queues with varying levels of control.

Push Operations Overview


Sources: src/Facades/Queue.php41-46

Push Method Signatures

MethodParametersDescription
push(object|string $job, mixed $data = '', ?string $queue = null)Job instance or class name, optional data, optional queue namePush job to queue immediately
pushOn(?string $queue, object|string $job, mixed $data = '')Queue name, job, optional dataPush to specific queue (queue-first signature)
pushRaw(string $payload, ?string $queue = null, array $options = [])Pre-serialized payload, optional queue, optionsPush raw payload without serialization
bulk(array $jobs, mixed $data = '', ?string $queue = null)Array of jobs, optional data, optional queuePush multiple jobs at once

Usage Examples:


Sources: src/Facades/Queue.php41-46

Delayed Job Execution

Jobs can be scheduled for execution after a specified delay using later() and laterOn() methods.

Delay Specification

Delays can be specified as:

  • Integer: Seconds from now
  • DateTimeInterface: Specific timestamp
  • DateInterval: Time interval from now

Sources: src/Facades/Queue.php44-45

Delayed Job Methods

MethodParametersDescription
later(DateInterval|DateTimeInterface|int $delay, object|string $job, mixed $data = '', ?string $queue = null)Delay, job, optional data, optional queueSchedule job for later execution
laterOn(?string $queue, DateInterval|DateTimeInterface|int $delay, object|string $job, mixed $data = '')Queue name, delay, job, optional dataSchedule job on specific queue

Usage Examples:


Sources: src/Facades/Queue.php44-45

Queue Inspection

The Queue facade provides methods for monitoring queue state and job counts across different states.

Queue State Methods

MethodReturn TypeDescription
size(?string $queue = null)intTotal number of jobs in queue
pendingSize(?string $queue = null)intNumber of pending (ready) jobs
delayedSize(?string $queue = null)intNumber of delayed jobs
reservedSize(?string $queue = null)intNumber of reserved (processing) jobs
creationTimeOfOldestPendingJob(?string $queue = null)?intUnix timestamp of oldest pending job

Queue State Diagram:


Usage Examples:


Sources: src/Facades/Queue.php36-40

Job Retrieval and Processing

Workers retrieve jobs from queues using the pop() method. The popUsing() method allows customizing job retrieval behavior.

Job Retrieval Flow


Sources: src/Facades/Queue.php47-86

Pop Methods

MethodParametersReturn TypeDescription
pop(?string $queue = null)Optional queue nameQueue\Contracts\Job|nullRetrieve next job from queue
Queue::popUsing(string $workerName, callable $callback)Worker name, callbackvoidRegister custom job retrieval callback

Worker Registration:

The popUsing() static method delegates to Worker::popUsing() to register custom callbacks for job retrieval:


Sources: src/Facades/Queue.php47-86

Job Lifecycle Hooks

The Queue system provides callbacks that fire at various points in the job lifecycle, allowing for logging, monitoring, and custom behavior.

Lifecycle Callback Methods

MethodTrigger PointCallback Parameters
before(mixed $callback)Before job processing beginsJob instance
after(mixed $callback)After job completes successfullyJob instance
exceptionOccurred(mixed $callback)When job throws exceptionJob instance, exception
looping(mixed $callback)Before each queue poll iterationNone
failing(mixed $callback)When job is failingJob instance, exception
stopping(mixed $callback)When worker is stoppingNone

Lifecycle Event Flow:


Usage Example:


Sources: src/Facades/Queue.php15-20

Job Configuration Methods

The Queue system provides methods for retrieving job-specific configuration such as retry attempts, backoff delays, and expiration times.

MethodParametersReturn TypeDescription
getJobTries(mixed $job)Job instancemixedGet max retry attempts for job
getJobBackoff(mixed $job)Job instancemixedGet backoff delay between retries
getJobExpiration(mixed $job)Job instancemixedGet job expiration time
createPayloadUsing(?callable $callback)CallbackvoidCustomize payload creation

Sources: src/Facades/Queue.php50-53

Driver Extension System

The Queue system uses the Manager pattern to support custom queue drivers through the extend() and addConnector() methods.

Driver Registration Flow


Sources: src/Facades/Queue.php23-24

Extension Methods

MethodParametersDescription
extend(string $driver, Closure $resolver)Driver name, resolver closureRegister custom driver resolver
addConnector(string $driver, Closure $resolver)Driver name, connector closureAdd custom connection factory

Custom Driver Example:


Sources: src/Facades/Queue.php23-24

Connection Pooling

The Queue manager supports connection pooling for drivers that benefit from connection reuse, particularly for Redis-based queues.

Poolable Driver Management

MethodParametersDescription
addPoolable(string $driver)Driver nameMark driver as supporting pooling
removePoolable(string $driver)Driver nameRemove driver from poolable list
getPoolables()NoneGet list of poolable drivers
setPoolables(array $poolables)Array of driver namesSet poolable drivers list

Connection Pool Lifecycle:


Sources: src/Facades/Queue.php32-35

Release Callbacks

Release callbacks control how connections are returned to the pool after use:

MethodParametersDescription
setReleaseCallback(string $driver, Closure $callback)Driver name, callbackSet connection release behavior
getReleaseCallback(string $driver)Driver nameGet release callback for driver

Sources: src/Facades/Queue.php30-31

Container and Configuration

The Queue system integrates with the PSR-11 container for dependency injection and configuration management.

Configuration Methods

MethodReturn TypeDescription
getContainer()ContainerInterfaceGet the service container
setContainer(ContainerInterface $container)QueueSet the service container
getConfig()arrayGet queue configuration
setConfig(array $config)QueueSet queue configuration
getApplication()ContainerInterfaceGet application container
setApplication(ContainerInterface $app)QueueManagerSet application container
getConnectionName()stringGet current connection name
setConnectionName(string $name)QueueSet connection name

Container Integration:


Sources: src/Facades/Queue.php28-112

Testing with Queue Fake

The Queue facade provides a fake() method for testing. See Queue Testing for comprehensive documentation on testing queue operations.

Quick Testing Reference

MethodPurpose
Queue::fake()Replace queue with fake for testing
Queue::assertPushed()Assert job was pushed
Queue::assertPushedOn()Assert job pushed to specific queue
Queue::assertNotPushed()Assert job was not pushed
Queue::assertNothingPushed()Assert no jobs were pushed

Basic Testing Example:


For detailed testing documentation including assertPushedWithChain(), assertClosurePushed(), except(), and other advanced testing features, see Queue Testing.

Sources: src/Facades/Queue.php58-104

Queue Method Reference Table

Complete Method Overview

CategoryMethods
Job Dispatchingpush(), pushOn(), pushRaw(), later(), laterOn(), bulk()
Job Retrievalpop(), popUsing()
Queue Inspectionsize(), pendingSize(), delayedSize(), reservedSize(), creationTimeOfOldestPendingJob()
Connectionsconnection(), connected(), getConnectionName(), setConnectionName()
Driver Managementextend(), addConnector(), getDefaultDriver(), setDefaultDriver(), getName()
PoolingaddPoolable(), removePoolable(), getPoolables(), setPoolables(), setReleaseCallback(), getReleaseCallback()
ConfigurationgetConfig(), setConfig(), getContainer(), setContainer(), getApplication(), setApplication()
Job ConfigurationgetJobTries(), getJobBackoff(), getJobExpiration(), createPayloadUsing()
Lifecycle Hooksbefore(), after(), exceptionOccurred(), looping(), failing(), stopping()
Testingfake(), except(), assertPushed(), assertPushedOn(), assertPushedWithChain(), assertPushedWithoutChain(), assertClosurePushed(), assertClosureNotPushed(), assertNotPushed(), assertCount(), assertNothingPushed(), pushed(), hasPushed(), shouldFakeJob(), pushedJobs(), serializeAndRestore()

Sources: src/Facades/Queue.php14-72