VOOZH about

URL: https://deepwiki.com/hypervel/devtool/9-job-and-queue-generators

⇱ Job and Queue Generators | hypervel/devtool | DeepWiki


Loading...
Menu

Job and Queue Generators

Purpose and Scope

This document covers the make:job command for generating queueable job classes in the Hypervel framework. Jobs represent units of work that can be pushed to a queue for asynchronous processing, enabling background task execution and improved application responsiveness.

For information about generating the database tables required for the queue system (jobs, batches, and failed jobs tables), see Queue System Table Migrations.

Sources: src/ConfigProvider.php20-69


Overview

The JobCommand generates job classes that implement queued task execution. These jobs can be dispatched to various queue backends (database, Redis, etc.) and processed asynchronously by queue workers. The command follows the standard generator pattern, extending GeneratorCommand from Hyperf's base devtool.

Command Registration

The JobCommand is registered through the ConfigProvider alongside other generator commands:


Sources: src/ConfigProvider.php39-82


Job Class Structure

Basic Job Template

Generated job classes follow a standard structure that includes:

ComponentPurpose
Class declarationDefines the job class name
ConstructorAccepts job parameters and initializes properties
handle() methodContains the job's execution logic
Queue traits/interfacesProvides queue functionality
Serialization supportEnables job storage and retrieval

Job Class Architecture


Sources: src/ConfigProvider.php20


Queue Integration

Database Queue Schema

When using the database queue driver, jobs are stored in a table with the following structure:















































ColumnTypePurpose
idbigIncrementsPrimary key for job identification
queuestring (indexed)Queue channel name (default, high, low, etc.)
payloadlongTextSerialized job object and metadata
attemptsunsignedTinyIntegerNumber of execution attempts
reserved_atunsignedInteger (nullable)Timestamp when worker claimed job
available_atunsignedIntegerTimestamp when job should be processed
created_atunsignedIntegerJob creation timestamp

Sources: src/Generator/stubs/jobs-table.stub1-34

Job Lifecycle Flow


Sources: src/Generator/stubs/jobs-table.stub16-24


Command Usage

Basic Syntax


Common Patterns

Use CaseCommand Example
Basic jobmake:job ProcessPodcast
Nested namespacemake:job Jobs/Media/ProcessPodcast
Email sendingmake:job SendWelcomeEmail
Data processingmake:job ImportCsvData
Cleanup tasksmake:job CleanupOldRecords

Job Dispatch Methods

Dispatch Strategies


Sources: src/Generator/stubs/jobs-table.stub18


Queue Table Dependencies

Related Migration Commands

The job generator works in conjunction with queue table migrations:


Table Name Configuration:

The jobs-table.stub uses a %TABLE% placeholder that is replaced with the configured table name. This allows customization of the queue table name through configuration:


Sources: src/Generator/stubs/jobs-table.stub16-32 src/ConfigProvider.php66-68


File Output Location

Default Namespace and Directory

AspectDefault Value
NamespaceApp\Jobs
Directoryapp/Jobs/
File naming{JobName}.php

Example Output Structure

app/
└── Jobs/
 ├── ProcessPodcast.php
 ├── SendWelcomeEmail.php
 └── Media/
 └── ProcessVideo.php

Sources: src/ConfigProvider.php20


Integration with Other Systems

Job Dependencies


Sources: src/ConfigProvider.php20-69 src/Generator/stubs/jobs-table.stub1-34


Queue Worker Execution

Worker Process Flow


Sources: src/Generator/stubs/jobs-table.stub16-24


Configuration Integration

Queue Configuration Access

Jobs interact with the queue system through configuration:

ConfigurationPurpose
queue.defaultDefault queue connection
queue.connections.database.tableJob queue table name
queue.connections.database.queueDefault queue name
queue.failed.tableFailed jobs table name
queue.batching.tableJob batches table name

Command to Configuration Mapping


Sources: src/ConfigProvider.php66-69 src/Generator/stubs/jobs-table.stub16


Best Practices

Job Design Guidelines

GuidelineRationale
Keep jobs focusedSingle responsibility, easier to debug
Make jobs idempotentSafe for retries after failures
Use type hintsEnable container auto-resolution
Avoid large payloadsMinimize serialization overhead
Set appropriate timeoutsPrevent worker hangs
Implement proper error handlingGraceful failure recovery

Job Naming Conventions

PatternExampleUse Case
Verb + NounProcessPodcastAction-oriented tasks
Send + SubjectSendWelcomeEmailNotification delivery
Generate + OutputGenerateReportData generation
Import/ExportImportUsersData transfer
Cleanup + TargetCleanupOldFilesMaintenance tasks

Sources: src/ConfigProvider.php20