Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
jpoz committed May 25, 2024
1 parent 336d084 commit 821d495
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 36 deletions.
10 changes: 1 addition & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ gen: ## Generate protobuf models
go generate ./...

.PHONY: gen_protos
gen_protos: gen_go_protos gen_python_protos ## Generate protobuf models
gen_protos: gen_go_protos ## Generate protobuf models


.PHONY: gen_go_protos
Expand All @@ -84,14 +84,6 @@ gen_go_protos:
--go-grpc_out=. --go-grpc_opt=paths=source_relative \
${PROTO_FILES}

gen_python_protos:
python -m grpc_tools.protoc -I wire --python_out=./libs/py/conveyor/wire --grpc_python_out=./libs/py/conveyor/wire wire/jobs.proto
protol \
--create-package \
--in-place \
--python-out ./libs/py/conveyor/wire \
protoc --proto-path=./wire wire/jobs.proto

## Test
.PHONY: test
test: ## Run tests
Expand Down
4 changes: 2 additions & 2 deletions _dev/dev.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 12 additions & 11 deletions _examples/basic/jobtypes.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions _examples/basic/jobtypes.proto
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
syntax = "proto3";
package basic;
package main;

option go_package = "github.com/jpoz/conveyor/examples/basic";
option go_package = "github.com/jpoz/conveyor/_examples/basic/main";

message BasicJob {
string name = 1;
Expand Down
64 changes: 58 additions & 6 deletions _examples/basic/work.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,68 @@
package basic
package main

import (
"context"
"fmt"
"log/slog"
"os"
sync "sync"

"github.com/jpoz/conveyor"
"github.com/jpoz/conveyor/config"
)

func RunBasicJob(ctx context.Context, arg *BasicJob) error {
slog.Info("starting job", slog.String("name", arg.Name), slog.Int("count", int(arg.Count)))
func main() {
cfg := &config.Project{
RedisURL: os.Getenv("REDIS_URL"),
Namespace: "TestBasic",
Logger: slog.Default(),
}

ctx := context.Background()

worker, err := conveyor.NewWorker(cfg)
if err != nil {
panic(err)
}

var wg sync.WaitGroup
RunBasicJob := func(ctx context.Context, arg *BasicJob) error {
slog.Info("starting job", slog.String("name", arg.Name), slog.Int("count", int(arg.Count)))

for i := int32(0); i < arg.Count; i++ {
slog.Info("running job", slog.String("name", arg.Name), slog.Int("count", int(i+1)))
}

for i := int32(0); i < arg.Count; i++ {
slog.Info("running job", slog.String("name", arg.Name), slog.Int("count", int(i)))
wg.Done()
return nil
}

return nil
worker.RegisterJobs(RunBasicJob)

go func() {
fmt.Println("running worker")
err = worker.Run(ctx)
if err != nil {
panic(err)
}
}()

client, err := conveyor.NewClient(cfg)
if err != nil {
return
}

wg.Add(1)
result, err := client.Enqueue(ctx, &BasicJob{
Name: "test",
Count: 5,
})
if err != nil {
panic(err)
}

fmt.Println("wait")
wg.Wait()

fmt.Printf("result id: %v\n", result.Uuid)
}
4 changes: 2 additions & 2 deletions fixtures/basic.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions fixtures/nested.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions wire/jobs.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 821d495

Please sign in to comment.