Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
hum committed Jan 15, 2024
1 parent cd9242a commit 0789f41
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,21 @@ defer scheduler.Stop()
// Add the task to the scheduler
scheduler.RegisterTask(task)
```
You can also bound the `Interval` with `MaxIter` to only allow N intervals to pass.
```go
task := scheduled.NewTask(scheduled.TaskOpts{
Fn: func() error {
fmt.Println("Hello from task!")
return nil
},
Interval: 10*time.Second,
// Stops executing after 10 runs
MaxIter: 10,
})
```

### With start time
You can also specify `Task.StartTime` to be in the future, therefore delaying the execution of the function until the specified time.
### With start time and end time
You can also specify `StartTime` and/or `EndTime` to time bound the task's execution. `StartTime` allows the scheduler to wait until the specified time to execute the function, while `EndTime` is used with interval or CRON to end the execution of the task after a certain period of time passes.
```go
task := scheduled.NewTask(scheduled.TaskOpts{
Fn: func() error {
Expand All @@ -39,11 +51,16 @@ task := scheduled.NewTask(scheduled.TaskOpts{
Interval: 10*time.Second,
// Starts the function in 5 hours, then runs it every 10 seconds
StartTime: time.Now().Add(5*time.Hour),
// Stops executing after 24 hours
EndTime: time.Now().Add(24*time.Hour),
})
```

### With CRON
A task supports a CRON syntax to act as the interval function. Use `Task.Cron` to pass in a CRON string.
A task supports a CRON syntax to act as the interval function. Use `Cron` to pass in a CRON string.


NOTE: `Cron` has a priority over `Interval`. If you pass both, `Cron` will be used.
```go
task := scheduled.NewTask(scheduled.TaskOpts{
Fn: func() error {
Expand Down

0 comments on commit 0789f41

Please sign in to comment.