Skip to content

Commit

Permalink
feat: Add support for reading from and writing to gzip files
Browse files Browse the repository at this point in the history
The code changes include adding a new example file `write-to-gzip-file/main.go` that demonstrates how to write to a gzip file. It also includes modifications to the `read-from-gzip-file/main.go` file, removing the `gojob.WithNumShards(4)` and `gojob.WithShard(0)` options. Additionally, the `go.mod` and `go.sum` files were updated to bump the `github.com/WangYihang/uio` dependency to version `v0.0.0-20240905152743-19ba2df5e6a6`.

Please remove any meta information and format the commit message according to the repository's guidelines.
  • Loading branch information
WangYihang committed Sep 5, 2024
1 parent 07cbd3d commit 36da724
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 5 deletions.
2 changes: 0 additions & 2 deletions examples/read-from-gzip-file/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
).
Expand Down
41 changes: 41 additions & 0 deletions examples/write-to-gzip-file/main.go
Original file line number Diff line number Diff line change
@@ -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()
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand Down

0 comments on commit 36da724

Please sign in to comment.