百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
S

scheduler

> 编程语言
开源

Golang 任务调度器

182 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

Golang 任务调度器

  • Go Task Scheduler [[https://travis-ci.org/rakanalh/scheduler][https://img.shields.io/travis/rakanalh/scheduler/master.svg?style=flat-square]] [[http://codecov.io/github/rakanalh/scheduler?branch=master][http://codecov.io/github/rakanalh/scheduler/coverage.svg?branch=master]] [[https://godoc.org/github.com/rakanalh/scheduler][https://img.shields.io/badge/godoc-reference-blue.svg?style=flat-square]] [[https://github.com/rakanalh/scheduler/blob/master/LICENSE.txt][https://img.shields.io/badge/License-MIT-orange.svg?style=flat-square]]

Go Task scheduler is a small library that you can use within your application that enables you to execute callbacks (goroutines) after a pre-defined amount of time. GTS also provides task storage which is used to invoke callbacks for tasks which couldn't be executed during down-time as well as maintaining a history of the callbacks that got executed.

** Features

  • Execute tasks based after a specific duration or at a specific point in time
  • Job stores for history & recovery, provided stores out of the box:
  • Sqlite3
  • Redis (Coming soon)
  • Installation

#+BEGIN_SRC shell go get github.com/rakanalh/scheduler #+END_SRC

  • How To Use

Instantiate a scheduler as follows:

#+BEGIN_SRC go s := scheduler.New(storage) #+END_SRC

GTS currently supports 2 kinds of storages:

  1. NoOpStorage: Does nothing

#+BEGIN_SRC go noOpStorage := storage.NewNoOpStorage() #+END_SRC 2. MemoryStorage: Does nothing #+BEGIN_SRC go memStorage := storage.NewMemoryStorage() #+END_SRC 2. SqliteStorage: Persists tasks into a SQLite3 database. #+BEGIN_SRC go sqliteStorage := storage.NewSqlite3Storage() #+END_SRC

Example: #+BEGIN_SRC go storage := storage.NewSqlite3Storage( storage.Sqlite3Config{ DbName: "db.store", }, ) if err := storage.Connect(); err != nil { log.Fatal("Could not connect to db", err) }

if err := storage.Initialize(); err != nil { log.Fatal("Could not intialize database", err) } #+END_SRC

and then pass it to the scheduler.

Scheduling tasks can be done in 3 ways:

** Execute a task after 5 seconds. #+BEGIN_SRC go func MyFunc(arg1 string, arg2 string) taskID := s.RunAfter(5*time.Second, MyFunc, "Hello", "World") #+END_SRC

** Execute a task at a specific time. #+BEGIN_SRC go func MyFunc(arg1 string, arg2 string) taskID := s.RunAt(time.Now().Add(24 * time.Hour), MyFunc, "Hello", "World") #+END_SRC

** Execute a task every 1 minute. #+BEGIN_SRC go func MyFunc(arg1 string, arg2 string) taskID := s.RunEvery(1 * time.Minute, MyFunc, "Hello", "World") #+END_SRC

  • Examples

The [[https://github.com/rakanalh/scheduler/tree/master/_example/][Examples]] folder contains a bunch of code samples you can look into.

  • Custom Storage

GTS supports the ability to provide a custom storage, the newly created storage has to implement the TaskStore interface

#+BEGIN_SRC go type TaskStore interface { Store(task *TaskAttributes) error Remove(task *TaskAttributes) error Fetch() ([]TaskAttributes, error) } #+END_SRC

TaskAttributes looks as follows: #+BEGIN_SRC go type TaskAttributes struct { Hash string Name string LastRun string NextRun string Duration string IsRecurring string Params string } #+END_SRC

  • TODOs
  • Design a cron-like task schedule for RunEvery method
  • Credit This package is heavily inspired by [[https://github.com/agronholm/apscheduler/][APScheduler]] for Python & [[https://github.com/jasonlvhit/gocron][GoCron]]

  • License

MIT

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Gocrongolangschedulertask

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言