Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/aodin/schedule
Schedule tasks in Go
https://github.com/aodin/schedule
Last synced: 13 days ago
JSON representation
Schedule tasks in Go
- Host: GitHub
- URL: https://github.com/aodin/schedule
- Owner: aodin
- License: mit
- Created: 2014-02-15T01:15:11.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2014-09-01T20:09:26.000Z (about 10 years ago)
- Last Synced: 2024-08-01T16:18:21.397Z (3 months ago)
- Language: Go
- Size: 217 KB
- Stars: 8
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
schedule
========Schedule jobs in Go using the `time` and `sync` packages.
Jobs must be niladic functions that return an error.
```go
func Heartbeat() error {
return nil
}
```More complex jobs can be built using methods.
```go
type Counter struct {
count int64
}
func (c *Counter) Count() error {
c.count += 1
return nil
}
```To repeat a job every hour for 24 times:
```go
schedule.RepeatN(Heartbeat, time.Hour, 24)
schedule.WaitForJobsToFinish()
```To repeat a job daily at 3:00 UTC:
```go
threeAM := schedule.MustParseClockUTC("3:00:00")
schedule.Daily(Heartbeat, threeAM)
schedule.WaitForJobsToFinish()
```To stop a job cleanly between iterations while it is running forever:
```go
job := schedule.Repeat(c.Count, time.Second)
go func() {
<- time.After(5 * time.Second)
job.Quit()
}()
schedule.WaitForJobsToFinish()
```For full API documentation visit the project's [GoDoc page](https://godoc.org/github.com/aodin/schedule).
-aodin, 2014