Skip to content

Commit

Permalink
docs: update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
WangYihang committed Mar 14, 2024
1 parent d25d34f commit ba618eb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ The whole [code](./examples/simple-http-crawler/main.go) looks like this.
package main

import (
"fmt"
"net/http"

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

type MyTask struct {
Expand All @@ -56,15 +56,18 @@ func (t *MyTask) Do() error {
}

func main() {
var numTotalTasks int64 = 256
scheduler := gojob.NewScheduler().
SetNumWorkers(8).
SetMaxRetries(4).
SetOutputFilePath("output.json").
SetMaxRuntimePerTaskSeconds(16).
SetNumShards(4).
SetShard(0).
SetTotalTasks(numTotalTasks).
Start()
for line := range util.Cat("input.txt") {
scheduler.Submit(New(line))
for i := range numTotalTasks {
scheduler.Submit(New(fmt.Sprintf("https://httpbin.org/task/%d", i)))
}
scheduler.Wait()
}
Expand Down
14 changes: 7 additions & 7 deletions examples/simple-http-crawler/main.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package main

import (
"fmt"
"net/http"

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

type MyTask struct {
Url string `json:"url"`
StatusCode int `json:"status_code"`
}

func NewTask(url string) *MyTask {
func New(url string) *MyTask {
return &MyTask{
Url: url,
}
Expand All @@ -29,18 +29,18 @@ func (t *MyTask) Do() error {
}

func main() {
inputFilePath := "data/input.txt"
total := utils.Count(utils.Cat(inputFilePath))
var numTotalTasks int64 = 256
scheduler := gojob.NewScheduler().
SetNumWorkers(8).
SetMaxRetries(4).
SetOutputFilePath("output.json").
SetMaxRuntimePerTaskSeconds(16).
SetNumShards(4).
SetShard(0).
SetTotalTasks(total).
SetTotalTasks(numTotalTasks).
Start()
for line := range utils.Cat("data/input.txt") {
scheduler.Submit(NewTask(line))
for i := range numTotalTasks {
scheduler.Submit(New(fmt.Sprintf("https://httpbin.org/task/%d", i)))
}
scheduler.Wait()
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/WangYihang/gojob

go 1.21
go 1.22

require (
github.com/google/uuid v1.6.0
Expand Down

0 comments on commit ba618eb

Please sign in to comment.