dtyq/task-scheduler
Composer 安装命令:
composer require dtyq/task-scheduler
包简介
README 文档
README
安装
composer require dtyq/task-scheduler
php bin/hyperf.php vendor:publish dtyq/task-scheduler
使用方式请见
\Dtyq\TaskScheduler\Service\TaskSchedulerDomainService
说明
仅支持分钟级调用
调度方式
- 定时调度
- 指定调度
创建调度任务
- 定时调度需要有个定时器去生成未来 n 小时内的需要执行的任务数据
- 根据任务时间生成调度任务
执行任务
- 执行已到时间的任务,改变状态,如果有误则执行报错事件
- 调度结束后,记录到归档表
后台执行
- 每天检测超过 n 天已完成的调度任务,删除。防止调度表过大
- 每分钟检测未来 n 天内需要执行的任务,生成调度任务
- 每分钟检测已到时间的任务,执行
数据库
- 任务调度表(task_scheduler) 用于具体执行的任务记录
- 任务归档表(task_scheduler_log) 用于保存已完成的任务记录,仅做归档,方便以后回档查看历史记录
- 定时任务表(task_scheduler_crontab) 用于保存定时任务规则
记得创建表结构
php bin/hyperf.php migrate
-- auto-generated definition create table task_scheduler ( id bigint unsigned not null primary key, external_id varchar(64) not null comment '业务 id', name varchar(64) not null comment '名称', expect_time datetime not null comment '预期执行时间', actual_time datetime null comment '实际执行时间', type tinyint default 2 not null comment '调度类型:1 定时调度,2 指定调度', cost_time int default 0 not null comment '耗时 毫秒', retry_times int default 0 not null comment '剩余重试次数', status tinyint default 0 not null comment '状态', callback_method json not null comment '回调方法', callback_params json not null comment '回调参数', remark varchar(255) default '' not null comment '备注', creator varchar(64) default '' not null comment '创建人', created_at datetime not null comment '创建时间' ) collate = utf8mb4_unicode_ci; create index task_scheduler_external_id_index on task_scheduler (external_id); create index task_scheduler_status_expect_time_index on task_scheduler (status, expect_time); -- auto-generated definition create table task_scheduler_crontab ( id bigint unsigned not null primary key, name varchar(64) not null comment '名称', crontab varchar(64) not null comment 'crontab表达式', last_gen_time datetime null comment '最后生成时间', enabled tinyint(1) default 1 not null comment '是否启用', retry_times int default 0 not null comment '总重试次数', callback_method json not null comment '回调方法', callback_params json not null comment '回调参数', remark varchar(255) default '' not null comment '备注', creator varchar(64) default '' not null comment '创建人', created_at datetime not null comment '创建时间' ) collate = utf8mb4_unicode_ci; -- auto-generated definition -- auto-generated definition create table task_scheduler_log ( id bigint unsigned not null primary key, task_id bigint unsigned not null comment '任务ID', external_id varchar(64) not null comment '业务标识', name varchar(64) not null comment '名称', expect_time datetime not null comment '预期执行时间', actual_time datetime null comment '实际执行时间', type tinyint default 2 not null comment '类型', cost_time int default 0 not null comment '耗时', status tinyint default 0 not null comment '状态', callback_method json not null comment '回调方法', callback_params json not null comment '回调参数', remark varchar(255) default '' not null comment '备注', creator varchar(64) default '' not null comment '创建人', created_at datetime not null comment '创建时间', result json null comment '结果' ) collate = utf8mb4_unicode_ci; create index task_scheduler_log_external_id_index on task_scheduler_log (external_id); create index task_scheduler_log_status_expect_time_index on task_scheduler_log (status, expect_time); create index task_scheduler_log_task_id_index on task_scheduler_log (task_id);
dtyq/task-scheduler 适用场景与选型建议
dtyq/task-scheduler 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8.33k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2025 年 04 月 06 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「hyperf」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 dtyq/task-scheduler 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 dtyq/task-scheduler 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 dtyq/task-scheduler 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
统计信息
- 总下载量: 8.33k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Apache
- 更新时间: 2025-04-06