Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
arcward committed Feb 26, 2024
1 parent b4a46c4 commit 66b4a19
Showing 1 changed file with 36 additions and 7 deletions.
43 changes: 36 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func main() {
schedule, err := crong.New("0 0 * * *", time.UTC)
if err != nil {
log.Fatal(err)
}
}

// Get the next (or most recent) scheduled time relative to the given time
fmt.Println("Next scheduled time:", schedule.Next(time.Now()))
Expand All @@ -30,7 +30,7 @@ func main() {
// Check if the given time satisfies the schedule
if schedule.Matches(time.Now()) {
fmt.Println("It's time!")
}
}
}
```

Expand All @@ -51,15 +51,15 @@ func main() {
schedule, err := crong.New("@hourly", time.UTC)
if err != nil {
log.Fatal(err)
}
}

ticker := crong.NewTicker(context.Background(), schedule, 1 * time.Minute)
defer ticker.Stop()

select {
case t := <-ticker.C:
log.Printf("%s: Tick!", t)
}
}
}
```

Expand All @@ -79,7 +79,7 @@ func main() {
schedule, err := crong.New("* * * * *", time.UTC)
if err != nil {
log.Fatal(err)
}
}

// MaxConcurrent=0 only allows the job to run sequentially, while
// increasing TickerReceiveTimeout can accommodate potentially long-running
Expand All @@ -98,8 +98,37 @@ func main() {
func(t time.Time) error {
log.Printf("Scheduled run for %s started at %s", t, time.Now())
return nil
},
)
},
)
defer scheduledJob.Stop(context.Background())
}
```

## Syntax

Supports standard cron syntax (see https://en.wikipedia.org/wiki/Cron), as well as less standard expressions.
For example, `5/10 4,5 * *` means "every 10 minutes starting at the 5th minute of the hour, for hours 4 and 5."

Days of the week are indexed 0-6, with 0 being Sunday, and can be referenced by
name (SUN, MON, TUE, WED, THU, FRI, SAT) or by number.

Months are indexed 1-12, and can be referenced by name
(JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC) or by number.

Cron macros supported:

- `@yearly` (or `@annually`) - Run once a year, midnight, Jan. 1
- `@monthly` - Run once a month, midnight, first of month
- `@weekly` - Run once a week, midnight between Saturday and Sunday
- `@daily` (or `@midnight`) - Run once a day, midnight
- `@hourly` - Run once an hour, beginning of hour

Other characters supported:

- `*`: Wildcard/Any value (ex: Every minute: `* * * * *`)
- `,`: Value list separator (ex: Minute 0 and 30 of every hour: `0,30 * * * *`)
- `-`: Range of values (ex: Minute 0-15 of every hour: `0-15 * * * *`)
- `/`: Step values (ex: Every 2nd minute from minute 10-20 of every hour: `10-20/2 * * * *`)
- `?`: No specific value (month, day of month, day of week only)
- `L`: Last day of month. When used, must be used alone in the day
field (ex: 12:30 on the last day of every month: `30 12 L * *`)

0 comments on commit 66b4a19

Please sign in to comment.