Skip to content

Commit

Permalink
Merge pull request #6 from Claudiu/master
Browse files Browse the repository at this point in the history
Make example work, fix README
  • Loading branch information
marksalpeter committed Dec 5, 2015
2 parents 4e960f8 + 980c96b commit b075c79
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 34 deletions.
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## goCron: A Golang Job Scheduling Package.

[![GoDoc](http://godoc.org/github.com/claudiu/gocron?status.png)](http://godoc.org/github.com/claudiu/gocron)
[![GoDoc](http://godoc.org/github.com/jasonlvhit/gocron?status.png)](http://godoc.org/github.com/jasonlvhit/gocron)

goCron is a Golang job scheduling package which lets you run Go functions periodically at pre-determined interval using a simple, human-friendly syntax.

Expand All @@ -14,24 +14,24 @@ Back to this package, you could just use this simple API as below, to run a cron

``` go
package main

import (
"fmt"
"github.com/claudiu/gocron"
"github.com/jasonlvhit/gocron"
)

func task() {
fmt.Println("I am runnning task.")
}

func taskWithParams(a int, b string) {
fmt.Println(a, b)
}

func main() {
// Do jobs with params
gocron.Every(1).Second().Do(taskWithParams, 1, "hello")

// Do jobs without params
gocron.Every(1).Second().Do(task)
gocron.Every(2).Seconds().Do(task)
Expand All @@ -41,34 +41,34 @@ func main() {
gocron.Every(2).Hours().Do(task)
gocron.Every(1).Day().Do(task)
gocron.Every(2).Days().Do(task)

// Do jobs on specific weekday
gocron.Every(1).Monday().Do(task)
gocron.Every(1).Thursday().Do(task)

// function At() take a string like 'hour:min'
gocron.Every(1).Day().At("10:30").Do(task)
gocron.Every(1).Monday().At("18:30").Do(task)

// remove, clear and next_run
_, time := gocron.NextRun()
fmt.Println(time)

gocron.Remove(task)
gocron.Clear()

// function Start start all the pending jobs
<- gocron.Start()

// also , you can create a your new scheduler,
// to run two scheduler concurrently
s := gocron.NewScheduler()
s.Every(3).Seconds().Do(task)
<- s.Start()

}
```
and full test cases and [document](http://godoc.org/github.com/claudiu/gocron) will be coming soon.
and full test cases and [document](http://godoc.org/github.com/jasonlvhit/gocron) will be coming soon.

Once again, thanks to the great works of Ruby clockwork and Python schedule package. BSD license is used, see the file License for detail.

Expand Down
22 changes: 5 additions & 17 deletions example/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"

"github.com/jasonlvhit/gocron"
)

Expand Down Expand Up @@ -39,28 +40,15 @@ func main() {
_, time := gocron.NextRun()
fmt.Println(time)

gocron.Remove(task)
gocron.Clear()
// gocron.Remove(task)
// gocron.Clear()

// function Start start all the pending jobs
gocron.Start()

// Run all and Run pending , Run all with delay
for {
gocron.RunAll()
}

for {
gocron.RunPending()
}

for {
gocron.RunAllwithDelay(2) // in second
}
<-gocron.Start()

// also , you can create a your new scheduler,
// to run two scheduler concurrently
s := gocron.NewScheduler()
s.Every(3).Seconds().Do(task)

<-s.Start()
}
4 changes: 2 additions & 2 deletions gocron.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,8 +506,8 @@ func RunAllwithDelay(d int) {
}

// Run all jobs that are scheduled to run
func Start() {
defaultScheduler.Start()
func Start() chan bool {
return defaultScheduler.Start()
}

// Clear
Expand Down

0 comments on commit b075c79

Please sign in to comment.