Skip to content

Commit

Permalink
docs: update example in README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
WangYihang committed Feb 27, 2024
1 parent 41b6b68 commit 492d2f8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ Create a job scheduler with a worker pool of size 32. To do this, you need to im
```go
// Task is an interface that defines a task
type Task interface {
// Do starts the task
// Do starts the task, returns error if failed
// If an error is returned, the task will be retried until MaxRetries
// You can set MaxRetries by calling SetMaxRetries on the scheduler
Do() error
}
```
Expand All @@ -29,6 +31,7 @@ import (
"net/http"

"github.com/WangYihang/gojob"
"github.com/WangYihang/gojob/pkg/util"
)

type MyTask struct {
Expand All @@ -53,8 +56,14 @@ func (t *MyTask) Do() error {
}

func main() {
scheduler := gojob.NewScheduler(1, 4, 8, "output.txt")
for line := range gojob.Cat("input.txt") {
scheduler := gojob.NewScheduler().
SetNumWorkers(8).
SetMaxRetries(4).
SetMaxRuntimePerTaskSeconds(16).
SetNumShards(4).
SetShard(0).
Start()
for line := range util.Cat("input.txt") {
scheduler.Submit(New(line))
}
scheduler.Wait()
Expand Down
4 changes: 3 additions & 1 deletion gojob.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import (

// Task is an interface that defines a task
type Task interface {
// Do starts the task
// Do starts the task, returns error if failed
// If an error is returned, the task will be retried until MaxRetries
// You can set MaxRetries by calling SetMaxRetries on the scheduler
Do() error
}

Expand Down

0 comments on commit 492d2f8

Please sign in to comment.