项目作者: kafji

项目描述 :
Schedule task to be executed periodically or at specified time.
高级语言: Go
项目地址: git://github.com/kafji/goalarm.git
创建时间: 2016-09-29T04:53:26Z
项目社区:https://github.com/kafji/goalarm

开源协议:MIT License

下载


goalarm

Build Status
codecov

Run job periodically or at specific time.
Job is a function that accept context.Context and return interface{} and error.
Job will be executed in different goroutine than the caller.
Cancel periodically executed job using cancel function returned from context.WithCancel(context.Background()). For more use case take a look at its tests.

Installation

  1. go get -u github.com/kafji/goalarm

Example

  1. ctx := context.Background()
  2. // Print "hello" in 10 seconds.
  3. goalarm.In(ctx, 10*time.Second, func(ctx context.Context) (interface{}, error) {
  4. fmt.Println("hello")
  5. return nil, nil
  6. })
  7. // Print "hello" every 10 seconds.
  8. goalarm.Every(ctx, 10*time.Second, 0, func(ctx context.Context) (interface{}, error) {
  9. fmt.Println("hello")
  10. return nil, nil
  11. })

Development

Run test

  1. go test $(go list ./... | grep -v /vendor/)