Configuration
Job Configuration
Configuration is done per-job via protected properties:
use WPZylos\Framework\Queue\Job;
class MyJob extends Job
{
// Maximum number of attempts before marking as failed
protected int $tries = 3;
// Seconds to wait before retrying a failed attempt
protected int $retryAfter = 60;
// Maximum execution time in seconds (uses set_time_limit)
protected int $timeout = 60;
// Queue name for routing/prioritization
protected string $queue = 'default';
public function handle(): void
{
// job logic
}
}
Property Reference
| Property | Type | Default | Description |
|---|---|---|---|
$tries | int | 3 | After this many failed attempts, the job is moved to the failures table |
$retryAfter | int | 60 | Delay in seconds before the job becomes available for the next attempt |
$timeout | int | 60 | Calls set_time_limit() before execution (if available) |
$queue | string | 'default' | Logical queue name; use different names for priority routing |
Cron Configuration
Batch Size
Control how many jobs are processed per WP-Cron invocation:
$cron = $app->make(QueueCronHandler::class);
$cron->setBatchSize(25); // Default: 10
Schedule Interval
The cron handler registers a custom "every minute" schedule. This is the minimum interval supported by WP-Cron. The actual execution frequency depends on site traffic (WP-Cron is triggered by page visits).
For more reliable cron execution, add a system cron job:
* * * * * wget -q -O /dev/null https://yoursite.com/wp-cron.php?doing_wp_cron
And disable the default WP-Cron in wp-config.php:
define('DISABLE_WP_CRON', true);
Queue Names
Use queue names to organize and prioritize jobs:
| Queue Name | Use Case | Suggested Batch Size |
|---|---|---|
default | General-purpose jobs | 10 |
emails | Email sending | 20 |
reports | Report generation | 5 |
urgent | Time-sensitive tasks | 25 |
low | Low-priority background tasks | 3 |
Process specific queues with the worker:
$worker = $app->make(Worker::class);
// Process urgent first, then default
$worker->run(25, 'urgent');
$worker->run(10, 'default');
$worker->run(3, 'low');
Database Table Prefix
Table names are generated by ContextInterface::tableName(), which typically prepends the WordPress table prefix and your plugin prefix:
wp_myplugin_queue_jobs
wp_myplugin_queue_failures
The exact prefix depends on your plugin's context configuration.