cron

command
v1.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 9, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

演示: 定时任务 + 雪花 ID —— Wire 一行装配 cron 与 snowflake, 零外部服务。

三个任务覆盖三种典型场景:

  1. 心跳任务: 高频短任务, 观察包内置的执行耗时日志
  2. 慢任务: 故意跑得比调度间隔久, 配合 skip_if_busy 演示"上一轮未跑完跳过本轮"
  3. 报表任务: 每分钟整点触发, 联动 snowflake 发号(任务内取全局句柄即可)

运行:

cd example/cron && go run .

观察日志(另开终端):

  • 每 5s 一条心跳日志; 每 2s 一次慢任务触发, 但多数被"跳过"(执行需 5s)
  • 每分钟第 0s 一条报表日志(带 snowflake ID)
  • 实时发号: curl http://127.0.0.1:8084/api/v1/next-id

停机: Ctrl+C —— Stop 会等待运行中的任务完成后再退出, 不会丢半个任务。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL