Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/krayzpipes/cronticker
Golang ticker that works with Cron scheduling.
https://github.com/krayzpipes/cronticker
Last synced: about 2 months ago
JSON representation
Golang ticker that works with Cron scheduling.
- Host: GitHub
- URL: https://github.com/krayzpipes/cronticker
- Owner: krayzpipes
- License: mit
- Created: 2020-11-28T20:59:38.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2021-01-02T01:57:05.000Z (almost 4 years ago)
- Last Synced: 2024-07-31T20:52:03.274Z (5 months ago)
- Language: Go
- Size: 23.4 KB
- Stars: 16
- Watchers: 4
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-go - cronticker - A ticker implementation to support cron schedules. (Job Scheduler / Search and Analytic Databases)
- awesome-go-extra - cronticker - 11-28T20:59:38Z|2021-01-02T01:57:05Z| (Job Scheduler / Advanced Console UIs)
README
# cronticker
Golang ticker that works with Cron scheduling.[![CircleCI](https://circleci.com/gh/circleci/circleci-docs.svg?style=shield)](https://circleci.com/gh/circleci/circleci-docs)
![Codecov](https://img.shields.io/codecov/c/github/krayzpipes/cronticker)
[![Go Report Card](https://goreportcard.com/badge/github.com/krayzpipes/cronticker)](https://goreportcard.com/report/github.com/krayzpipes/cronticker)
## Import it```bash
go get github.com/krayzpipes/cronticker/cronticker
``````go
import "github.com/krayzpipes/cronticker/cronticker"
```## Usage
Create a new ticker:
```go
ticker, err := NewTicker("TZ=America/New_York 0 0 0 ? * SUN")
```Check the ticker's channel for the next tick:
```go
tickerTime := <-ticker.C
```Reset the ticker to a new cron schedule
```go
err := ticker.Reset("0 0 0 ? * MON,TUE,WED")
```Stop the ticker
```go
ticker.Stop()
```Use `defer ticker.Stop()` whenever you can to ensure the cleanup of goroutines.
```go
ticker, _ := NewTicker("@daily")
defer ticker.Stop()
```### Cron Schedule Format
The Cron schedule can be in **Unix** or **Quartz** format. Directives like
'@weekly' or '@daily' can also be parsed as defined in the
package github.com/robfig/cron/v3.You may add the TimeZone/location to the beginning of the cron schedule
to change the time zone. Default is UTC if `TZ=Whatever` is not prepended
to the cron schedule.#### Examples
| Cron Schedule | Type/Format | Description |
|---------------|------|-------------|
|"TZ=America/Los_Angeles 0 0 * * *"|Unix|Daily at 12 AM in Los Angeles|
|"TZ=America/Los_Angeles 0 0 0 ? * MON"|Quartz|Mondays at 12 AM in Los Angeles|
|"TZ=America/Los_Angeles @daily"|Directive|Daily at 12 AM in Los Angeles|
|"@daily"|Directive|Daily at 12 AM UTC|You may also use the following characters:
| Character | Description | Example |
|-----------|-------------|---------|
|-|Range|4-5|
|/|Step|0/5|
|*|Any|*/5|
|,|List|1,4,5|