-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5d61082
commit 811fa9c
Showing
3 changed files
with
55 additions
and
2 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package main | ||
|
||
import ( | ||
"math/rand" | ||
"time" | ||
|
||
"github.com/WangYihang/gojob" | ||
"github.com/WangYihang/gojob/pkg/utils" | ||
) | ||
|
||
type MyTask struct { | ||
Line string | ||
} | ||
|
||
func New(line string) *MyTask { | ||
return &MyTask{ | ||
Line: line, | ||
} | ||
} | ||
|
||
func (t *MyTask) Do() error { | ||
time.Sleep(time.Duration(rand.Intn(1000)) * time.Millisecond) | ||
return nil | ||
} | ||
|
||
func main() { | ||
scheduler := gojob.New( | ||
gojob.WithNumWorkers(8), | ||
gojob.WithMaxRetries(4), | ||
gojob.WithMaxRuntimePerTaskSeconds(16), | ||
gojob.WithNumShards(4), | ||
gojob.WithShard(0), | ||
gojob.WithResultFilePath("-"), | ||
gojob.WithStatusFilePath("status.json"), | ||
). | ||
Start() | ||
for line := range utils.Cat("data.txt.gz") { | ||
scheduler.Submit(New(line)) | ||
} | ||
scheduler.Wait() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters