{"id":13700077,"url":"https://github.com/Littlesqx/aint-queue","last_synced_at":"2025-05-04T18:34:11.353Z","repository":{"id":35095887,"uuid":"202512908","full_name":"Littlesqx/aint-queue","owner":"Littlesqx","description":":rocket: An async-queue library built on top of swoole, flexable multi-consumer, coroutine supported. 基于 Swoole 的一个异步队列库，可弹性伸缩的工作进程池，工作进程协程支持。","archived":true,"fork":false,"pushed_at":"2022-03-04T06:05:04.000Z","size":539,"stargazers_count":178,"open_issues_count":7,"forks_count":32,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-19T04:19:43.208Z","etag":null,"topics":["async","async-queue","coroutine","job","php7","queue","swoole","worker"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Littlesqx.png","metadata":{"files":{"readme":"README-ZH.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-08-15T09:26:11.000Z","updated_at":"2024-11-15T03:45:58.000Z","dependencies_parsed_at":"2022-08-24T09:22:11.270Z","dependency_job_id":null,"html_url":"https://github.com/Littlesqx/aint-queue","commit_stats":null,"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Littlesqx%2Faint-queue","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Littlesqx%2Faint-queue/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Littlesqx%2Faint-queue/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Littlesqx%2Faint-queue/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Littlesqx","download_url":"https://codeload.github.com/Littlesqx/aint-queue/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252382891,"owners_count":21739236,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["async","async-queue","coroutine","job","php7","queue","swoole","worker"],"created_at":"2024-08-02T20:00:48.212Z","updated_at":"2025-05-04T18:34:06.998Z","avatar_url":"https://github.com/Littlesqx.png","language":"PHP","readme":"# Aint Queue\n\n[![Build Status](https://travis-ci.org/Littlesqx/aint-queue.svg?branch=master)](https://travis-ci.org/Littlesqx/aint-queue)\n![License](https://img.shields.io/github/license/littlesqx/aint-queue)\n![Php version](https://img.shields.io/packagist/php-v/littlesqx/aint-queue)\n![Version](https://img.shields.io/github/v/release/littlesqx/aint-queue)\n \n基于 Swoole 的一个异步队列库，可弹性伸缩的工作进程池，工作进程协程支持。\u003ca href=\"README.md\"\u003eEnglish README\u003c/a\u003e\n\n![queue_status.gif](https://i.loli.net/2020/03/20/BTeJ8EQ1jyRxs7X.gif)\n\n## 特性\n\n- 默认 Redis 驱动\n- 秒级延时任务\n- 自定义重试次数和时间\n- 自定义错误回调\n- 支持任务执行中间件\n- 自定义队列快照事件\n- 弹性多进程消费\n- 工作进程协程支持\n- 漂亮的仪表盘\n\n## 环境\n\n- PHP 7.2+\n- Swoole 4.4+\n- Redis 3.2+ (redis 驱动)\n\n## 安装\n\n```shell\ncomposer require littlesqx/aint-queue -vvv\n```\n\n## 使用\n\n### 配置\n\n默认读取配置路径： `config/aint-queue.php`， 不存在时读取 `/vendor/littlesqx/aint-queue/src/Config/config.php` 。\n\n```php\n\u003c?php\n\nuse Littlesqx\\AintQueue\\Driver\\Redis\\Queue as RedisQueue;\nuse Littlesqx\\AintQueue\\Logger\\DefaultLogger;\n\nreturn [\n    // channel_name =\u003e [...config]\n    'default' =\u003e [\n        'driver' =\u003e [\n            'class' =\u003e RedisQueue::class,\n            'connection' =\u003e [\n                'host' =\u003e '127.0.0.1',\n                'port' =\u003e 6379,\n                'database' =\u003e '0',\n                // 'password' =\u003e 'password',\n            ],\n        ],\n        'logger' =\u003e [\n            'class' =\u003e DefaultLogger::class,\n            'options' =\u003e [\n                'level' =\u003e \\Monolog\\Logger::DEBUG,\n            ],\n        ],\n        'pid_path' =\u003e '/var/run/aint-queue',\n        'consumer' =\u003e [\n            'sleep_seconds' =\u003e 1,\n            'memory_limit' =\u003e 96,\n            'dynamic_mode' =\u003e true,\n            'capacity' =\u003e 6,\n            'flex_interval' =\u003e 5 * 60,\n            'min_worker_number' =\u003e 5,\n            'max_worker_number' =\u003e 30,\n            'max_handle_number' =\u003e 0,\n        ],\n        'job_snapshot' =\u003e [\n            'interval' =\u003e 5 * 60,\n            'handler' =\u003e [],\n        ],\n    ],\n];\n\n```\n\n所有参数：\n\n| name | type | comment | default |\n| :---- | :---- | :---- | :---- |\n| channel | string | 频道。队列的单位，每个频道内的消息对应着各自的消费者和生产者。支持多频道。在命令行使用 `--channel` 参数。 | default |\n| driver.class | string | 队列驱动类，需要实现 QueueInterface。 | Redis |\n| driver.connection | map | 驱动配置。 | |\n| pid_path | string | 主进程的 PID 文件存储路径。注意运行用户需要可读写权限。 | /var/run/aint-queue |\n| consumer.sleep_seconds | int | 当任务空闲时，每次 pop 操作后的睡眠秒数。 | 1 |\n| consumer.memory_limit | int | 工作进程的最大使用内存，超出则重启。单位 MB。| 96 |\n| consumer.dynamic_mode | bool | 是否开启自动伸缩工作进程。 | true |  \n| consumer.capacity | int | 代表每个工作进程在短时间内并且健康状态下的最多处理消息数，它影响了工作进程的自动伸缩策略。 | 5 |\n| consumer.flex_interval | int | 每 `flex_interval` 秒，监控进程尝试调整工作进程数（假设开启了自动伸缩工作进程）。 | 5 |\n| consumer.min_worker_number | int | 工作进程最小数目。 | 5 |\n| consumer.max_worker_number | int | 工作进程最大数目。 | 30 |\n| consumer.max_handle_number | int | 当前工作进程最大处理消息数，超出后重启。0 代表无限制。| 0 |\n| job_snapshot | map | 每隔 `job_snapshot.interval` 秒，`job_snapshot.handles` 会被依次执行。`job_snapshot.handles` 需要实现 JobSnapshotterInterface。| |\n\n### 消息推送\n\n可以在 cli/fpm 运行模式下使用：\n\n```php\n\u003c?php\n\nuse Littlesqx\\AintQueue\\Driver\\DriverFactory;\n\n$queue = DriverFactory::make($channel, $options);\n\n// push a job\n$queue-\u003epush(function () {\n    echo \"Hello aint-queue\\n\";\n});\n\n// push a delay job\n$closureJob = function () {\n    echo \"Hello aint-queue delayed\\n\";\n};\n$queue-\u003epush($closureJob, 5);\n\n```\n\n更建议使用类任务，这样功能上会更加完整，也可以获得更好的编码体验和性能。\n\n- 创建的任务类需要实现 `JobInterface`，详细可参考 `/example`。\n  - handle (): void: 任务主体，你要执行的内容，在这里可以使用 swoole 的相关 api（比如创建协程等）\n  - canRetry (int $attempt, $error): bool: 决定是否要重试\n  - retryAfter (int $attempt): int: 决定重试延时时间\n  - failed (int $id, array $payload): void: 任务彻底失败了（就是达到了重试次数还没成功）\n  - middleware (): array: 当前任务的中间件列表，原理参考 laravel pipeline 流水线\n\n\n- 注意任务必须能在生产者和消费者中（反）序列化，意味着需要在同一个项目；任务序列化后不含临时性资源（数据库连接等）、尽可能小（不要定义没必要的成员变量）。\n- 利用队列快照事件你可以实现队列实时监控，而利用任务中间件，你可以实现任务执行速率限制，任务执行日志等。\n\n### 队列管理\n\n推荐使用 `Supervisor` 等进程管理工具守护工作进程。\n\n```bash\nvendor/bin/aint-queue\n```\n\n```bash\nAintQueue Console Tool\n\nUsage:\n  command [options] [arguments]\n\nOptions:\n  -h, --help            Display this help message\n  -q, --quiet           Do not output any message\n  -V, --version         Display this application version\n      --ansi            Force ANSI output\n      --no-ansi         Disable ANSI output\n  -n, --no-interaction  Do not ask any interactive question\n  -v|vv|vvv, --verbose  Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug\n\nAvailable commands:\n  help                 Displays help for a command\n  list                 Lists commands\n queue\n  queue:clear          Clear the queue.\n  queue:dashboard      Start http server for dashboard.\n  queue:reload-failed  Reload all the failed jobs onto the waiting queue.\n  queue:status         Get the execute status of specific queue.\n worker\n  worker:listen        Listen the queue.\n  worker:reload        Reload worker for the queue.\n  worker:run           Run the specific job.\n  worker:stop          Stop listening the queue.\n```\n\n## 测试\n\n```bash\ncomposer test\n```\n## 贡献\n\n可以通过以下方式贡献：\n\n1. 通过 [issue tracker](https://github.com/littlesqx/aint-queue/issues) 提交 bug 或者建议给我们。\n2. 回答 [issue tracker](https://github.com/littlesqx/aint-queue/issues) 中的问题或者修复 bug。\n3. 更新和完善文档，或者提交一些改进的代码给我们。\n\n贡献没有什么特别的要求，只需要保证编码风格遵循 PSR2/PSR12，排版遵循 [中文文案排版指北](https://github.com/sparanoid/chinese-copywriting-guidelines)。\n\n## License\n\nMIT\n","funding_links":[],"categories":["Tasks and Queues"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FLittlesqx%2Faint-queue","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FLittlesqx%2Faint-queue","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FLittlesqx%2Faint-queue/lists"}