Skip to content

Commit

Permalink
add example for job.weekdays() and tweak scheduler week examlpes, go …
Browse files Browse the repository at this point in the history
…mod tidy (go-co-op#166)
  • Loading branch information
JohnRoesler authored Apr 28, 2021
1 parent b2ca6a6 commit 43b85a0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
18 changes: 15 additions & 3 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,14 @@ func ExampleJob_Weekday() {
// job not scheduled weekly on a weekday
}

func ExampleJob_Weekdays() {
s := gocron.NewScheduler(time.UTC)
j, _ := s.Every(1).Week().Monday().Wednesday().Friday().Do(task)
fmt.Println(j.Weekdays())
// Output:
// [Monday Wednesday Friday]
}

// ---------------------------------------------------------------------
// -------------------SCHEDULER-FUNCTIONS-------------------------------
// ---------------------------------------------------------------------
Expand Down Expand Up @@ -642,34 +650,38 @@ func ExampleScheduler_Week() {

_, _ = s.Every(1).Week().Do(task)
_, _ = s.Every(1).Weeks().Do(task)

_, _ = s.Every(1).Week().Monday().Wednesday().Friday().Do(task)
}

func ExampleScheduler_Weekday() {
s := gocron.NewScheduler(time.UTC)

_, _ = s.Every(1).Week().Weekday(time.Monday).Do(task)
_, _ = s.Every(1).Weeks().Weekday(time.Tuesday).Do(task)
_, _ = s.Every(1).Weeks().Weekday(time.Tuesday).Weekday(time.Friday).Do(task)
}

func ExampleScheduler_Weeks() {
s := gocron.NewScheduler(time.UTC)

_, _ = s.Every(1).Week().Do(task)
_, _ = s.Every(1).Weeks().Do(task)

_, _ = s.Every(2).Weeks().Monday().Wednesday().Friday().Do(task)
}

func ExampleScheduler_RunByTag() {
s := gocron.NewScheduler(time.UTC)
_, _ = s.Every(1).Day().At("10:00").Do(task)
_, _ = s.Every(2).Day().Tag("tag").At("10:00").Do(task)
s.StartAsync()
s.RunByTag("tag")
_ = s.RunByTag("tag")
}

func ExampleScheduler_RunByTagWithDelay() {
s := gocron.NewScheduler(time.UTC)
_, _ = s.Every(1).Day().Tag("tag").At("10:00").Do(task)
_, _ = s.Every(2).Day().Tag("tag").At("10:00").Do(task)
s.StartAsync()
s.RunByTagWithDelay("tag", 2*time.Second)
_ = s.RunByTagWithDelay("tag", 2*time.Second)
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/go-co-op/gocron
go 1.16

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/robfig/cron/v3 v3.0.1
github.com/stretchr/testify v1.7.0
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
Expand Down
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
Expand Down

0 comments on commit 43b85a0

Please sign in to comment.