PHPackages                             dtyq/task-scheduler - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. dtyq/task-scheduler

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

dtyq/task-scheduler
===================

v0.1.3(6mo ago)27.8k↓32.8%1Apache License 2.0PHPPHP &gt;=8.1CI failing

Since Apr 5Pushed 6mo ago1 watchersCompare

[ Source](https://github.com/dtyq/task-scheduler)[ Packagist](https://packagist.org/packages/dtyq/task-scheduler)[ RSS](/packages/dtyq-task-scheduler/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (3)Dependencies (13)Versions (5)Used By (0)

dtyq/task-scheduler
===================

[](#dtyqtask-scheduler)

安装
--

[](#安装)

```
composer require dtyq/task-scheduler
php bin/hyperf.php vendor:publish dtyq/task-scheduler

```

使用方式请见
------

[](#使用方式请见)

```
\Dtyq\TaskScheduler\Service\TaskSchedulerDomainService

```

说明
--

[](#说明)

> 仅支持分钟级调用

调度方式

1. 定时调度
2. 指定调度

创建调度任务

1. 定时调度需要有个定时器去生成未来 n 小时内的需要执行的任务数据
2. 根据任务时间生成调度任务

执行任务

1. 执行已到时间的任务，改变状态，如果有误则执行报错事件
2. 调度结束后，记录到归档表

后台执行

1. 每天检测超过 n 天已完成的调度任务，删除。防止调度表过大
2. 每分钟检测未来 n 天内需要执行的任务，生成调度任务
3. 每分钟检测已到时间的任务，执行

数据库

1. 任务调度表(task\_scheduler) 用于具体执行的任务记录
2. 任务归档表(task\_scheduler\_log) 用于保存已完成的任务记录，仅做归档，方便以后回档查看历史记录
3. 定时任务表(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);
```

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance66

Regular maintenance activity

Popularity28

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

 Bus Factor1

Top contributor holds 75% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~80 days

Total

4

Last Release

204d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1bdf9390d85a45dad64fe58584f55824c12a134a04e338d6259845683d9db137?d=identicon)[twosee](/maintainers/twosee)

---

Top Contributors

[![lihq1403](https://avatars.githubusercontent.com/u/25847339?v=4)](https://github.com/lihq1403 "lihq1403 (3 commits)")[![liaobw](https://avatars.githubusercontent.com/u/79210462?v=4)](https://github.com/liaobw "liaobw (1 commits)")

---

Tags

phphyperf

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/dtyq-task-scheduler/health.svg)

```
[![Health](https://phpackages.com/badges/dtyq-task-scheduler/health.svg)](https://phpackages.com/packages/dtyq-task-scheduler)
```

###  Alternatives

[xmo/mine-core

mineadmin core package

1686.1k1](/packages/xmo-mine-core)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
