pnixx/delayed_job
最新稳定版本:3.0.2
Composer 安装命令:
composer require pnixx/delayed_job
包简介
Async Delayed Job for PHP
关键字:
README 文档
README
Simple, efficient background processing for PHP uses threads to handle many jobs.
Requirements
- PHP 8.1+
- Redis 2.2+
- Composer
Installation
composer require pnixx/delayed_job
Worker process
Simple run worker process in background:
bin/run start
Extend run worker process:
bin/run start --process 5 --queue mailer -i /path/to/init.php
For list all commands, please use --help or -h argument.
For restart process after deploy use --restart or -r argument. A new process will be waiting finish all running processes.
Jobs
Job class required include perform method:
class TestJob extends PNixx\DelayedJob\Job { public function perform($args = []): void { //Work process } }
Any exception thrown by a job will be returned job to work with timeout.
If you want set limit attempt for retries job, set $attempt in you class.
Jobs can also have setup and completed methods. If a setup method is defined, it will be called before the perform method.
The completed method will be called after success job.
class TestJob extends PNixx\DelayedJob\Job { /** * Queue for publishing Job */ public static string $queue = 'mailer'; /** * Attempt count used for only delayed tasks * default: 0 - always repeat until it reach success */ public static $attempt = 0; public function setup() { //Setup this job } public function perform($args = []): void { //Work process } public function completed() { //Complete job callback } }
Queueing jobs
Jobs can run in current thread uses now method. If you use this, you can handle the exceptions in a job failing.
//Run job in this thread without arguments TestJob::now(); //Run job in this thread with arguments TestJob::now(['name' => 'Jane']);
Jobs can run in a background thread or add to scheduler.
//Run job in a background TestJob::later(); //Run job in a background with arguments TestJob::later(['name' => 'Jane']); //Add job in a scheduler. TestJob::later(['name' => 'Jane'], strtotime('+1 day'));
Signals
QUIT- Wait for job to finish processing then exitTERM/INT- Immediately kill job then exit without saving data
Author
Sergey Odintsov, @pnixx
统计信息
- 总下载量: 2.21k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 1
其他信息
- 授权协议: MIT
- 更新时间: 2016-08-10