diff --git a/examples/read-from-gzip-file/main.go b/examples/read-from-gzip-file/main.go index db7e282..d22022d 100644 --- a/examples/read-from-gzip-file/main.go +++ b/examples/read-from-gzip-file/main.go @@ -28,8 +28,6 @@ func main() { gojob.WithNumWorkers(8), gojob.WithMaxRetries(4), gojob.WithMaxRuntimePerTaskSeconds(16), - gojob.WithNumShards(4), - gojob.WithShard(0), gojob.WithResultFilePath("-"), gojob.WithStatusFilePath("status.json"), ). diff --git a/examples/write-to-gzip-file/main.go b/examples/write-to-gzip-file/main.go new file mode 100644 index 0000000..ecf0435 --- /dev/null +++ b/examples/write-to-gzip-file/main.go @@ -0,0 +1,41 @@ +package main + +import ( + "fmt" + "math/rand" + "time" + + "github.com/WangYihang/gojob" +) + +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) + fmt.Println(t.Line) + return nil +} + +func main() { + scheduler := gojob.New( + gojob.WithNumWorkers(1), + gojob.WithMaxRetries(4), + gojob.WithMaxRuntimePerTaskSeconds(16), + gojob.WithResultFilePath("result.txt.gz"), + gojob.WithStatusFilePath("status.json"), + gojob.WithMetadataFilePath("status.json"), + ). + Start() + for line := range 16 { + scheduler.Submit(New(fmt.Sprintf("line-%d", line))) + } + scheduler.Wait() +} diff --git a/go.mod b/go.mod index 579d536..c787eed 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/WangYihang/gojob go 1.22.6 require ( - github.com/WangYihang/uio v0.0.0-20240829150037-ce8fff04fa48 + github.com/WangYihang/uio v0.0.0-20240905152743-19ba2df5e6a6 github.com/google/uuid v1.6.0 github.com/jessevdk/go-flags v1.5.0 github.com/prometheus/client_golang v1.19.0 diff --git a/go.sum b/go.sum index 98f85db..0b6f4a9 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -github.com/WangYihang/uio v0.0.0-20240829150037-ce8fff04fa48 h1:PUBSQ5ANsRjj6g0jYPKVIo5m50iTS6gxY6TfCl29Rhk= -github.com/WangYihang/uio v0.0.0-20240829150037-ce8fff04fa48/go.mod h1:T4KtUOTAaSgFJNlU8mEMi5tPSUM1P8Fe1SrjMUwbxZ4= +github.com/WangYihang/uio v0.0.0-20240905152743-19ba2df5e6a6 h1:4r+fK+dAO7ry5gtFV6emxvcwP9sE8QT8UnPfGqlaD6g= +github.com/WangYihang/uio v0.0.0-20240905152743-19ba2df5e6a6/go.mod h1:5WoqViIAdldkfhEyOaceDjpfH4wazQDLz86aJVnHnGQ= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/caarlos0/env v3.5.0+incompatible h1:Yy0UN8o9Wtr/jGHZDpCBLpNrzcFLLM2yixi/rBrKyJs=