Skip to content

Commit

Permalink
Move out independent utils packages (#206)
Browse files Browse the repository at this point in the history
* Move out utils/executor package

* Move out utils/pubsub package

* Move out utils/kafka package

* Move out utils/worker package

* Move out utils/migrator package

* Move out utils/httptripper package

* Remove packages from doc generation

* Remove worker examples

* Move out utils/spanutils package
  • Loading branch information
achichen authored Mar 21, 2023
1 parent e4828b8 commit 6eb9a3d
Show file tree
Hide file tree
Showing 36 changed files with 4 additions and 3,342 deletions.
23 changes: 0 additions & 23 deletions builder/ServiceName/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ import (
"log"
"net/http"
"strings"
"time"

proto "github.com/carousell/Orion/builder/ServiceName/ServiceName_proto"
"github.com/carousell/Orion/interceptors"
"github.com/carousell/Orion/utils/headers"
"github.com/carousell/Orion/utils/worker"
"github.com/gorilla/mux"
grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
"google.golang.org/grpc"
Expand All @@ -27,7 +25,6 @@ type svc struct {
appendText string
debug bool
client proto.ServiceNameClient
worker worker.Worker
}

func (s *svc) GetRequestHeaders() []string {
Expand All @@ -47,29 +44,10 @@ func GetService(config Config) proto.ServiceNameServer {
log.Fatalln("did not connect: ", err)
}
s.client = proto.NewServiceNameClient(conn)
wConfig := worker.Config{}
wConfig.LocalMode = true
/*
wConfig.RabbitConfig = new(worker.RabbitMQConfig)
wConfig.RabbitConfig.Host = "192.168.99.100"
wConfig.RabbitConfig.QueueName = "test"
wConfig.RabbitConfig.UserName = "guest"
wConfig.RabbitConfig.Password = "guest"
*/
s.worker = worker.NewWorker(wConfig)
s.worker.RegisterTask("TestWorker", func(ctx context.Context, payload string) error {
time.Sleep(time.Millisecond * 200)
log.Println("worker", payload)
return nil
})
s.worker.RunWorker("Worker", 1)
return s
}

func DestroyService(obj interface{}) {
if s, ok := obj.(*svc); ok {
s.worker.CloseWorker()
}
}

func (s *svc) Echo(ctx context.Context, req *proto.EchoRequest) (*proto.EchoResponse, error) {
Expand Down Expand Up @@ -106,7 +84,6 @@ func (s *svc) Upper(ctx context.Context, req *proto.UpperRequest) (*proto.UpperR
defer sp.End()
time.Sleep(100 * time.Millisecond)
*/
go s.worker.Schedule(ctx, "TestWorker", req.GetMsg())
return resp, nil
}

Expand Down
30 changes: 4 additions & 26 deletions example/echo/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ import (
"log"
"net/http"
"strings"
"time"

proto "github.com/carousell/Orion/example/echo/echo_proto"
"github.com/carousell/Orion/interceptors"
"github.com/carousell/Orion/utils/headers"
"github.com/carousell/Orion/utils/worker"
"github.com/gorilla/mux"
grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
"google.golang.org/grpc"

proto "github.com/carousell/Orion/example/echo/echo_proto"
"github.com/carousell/Orion/interceptors"
"github.com/carousell/Orion/utils/headers"
)

const (
Expand All @@ -27,7 +26,6 @@ type svc struct {
appendText string
debug bool
client proto.EchoServiceClient
worker worker.Worker
}

func (s *svc) GetRequestHeaders() []string {
Expand All @@ -47,29 +45,10 @@ func GetService(config Config) proto.EchoServiceServer {
log.Fatalln("did not connect: %v", err)
}
s.client = proto.NewEchoServiceClient(conn)
wConfig := worker.Config{}
wConfig.LocalMode = true
/*
wConfig.RabbitConfig = new(worker.RabbitMQConfig)
wConfig.RabbitConfig.Host = "192.168.99.100"
wConfig.RabbitConfig.QueueName = "test"
wConfig.RabbitConfig.UserName = "guest"
wConfig.RabbitConfig.Password = "guest"
*/
s.worker = worker.NewWorker(wConfig)
s.worker.RegisterTask("TestWorker", func(ctx context.Context, payload string) error {
time.Sleep(time.Millisecond * 200)
log.Println("worker", payload)
return nil
})
s.worker.RunWorker("Worker", 1)
return s
}

func DestroyService(obj interface{}) {
if s, ok := obj.(*svc); ok {
s.worker.CloseWorker()
}
}

func (s *svc) Echo(ctx context.Context, req *proto.EchoRequest) (*proto.EchoResponse, error) {
Expand Down Expand Up @@ -106,7 +85,6 @@ func (s *svc) Upper(ctx context.Context, req *proto.UpperRequest) (*proto.UpperR
defer sp.End()
time.Sleep(100 * time.Millisecond)
*/
go s.worker.Schedule(ctx, "TestWorker", req.GetMsg())
return resp, nil
}

Expand Down
7 changes: 0 additions & 7 deletions utils/documentation.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,7 @@ package utils

// This comment block (re)generates the documentation.
//go:generate godoc2ghmd -ex -file=README.md github.com/carousell/Orion/utils
//go:generate godoc2ghmd -ex -file=executor/README.md github.com/carousell/Orion/utils/executor
//go:generate godoc2ghmd -ex -file=headers/README.md github.com/carousell/Orion/utils/headers
//go:generate godoc2ghmd -ex -file=httptripper/README.md github.com/carousell/Orion/utils/httptripper
//go:generate godoc2ghmd -ex -file=httptripper/retry/README.md github.com/carousell/Orion/utils/httptripper/retry
//go:generate godoc2ghmd -ex -file=httptripper/strategy/README.md github.com/carousell/Orion/utils/httptripper/strategy
//go:generate godoc2ghmd -ex -file=listenerutils/README.md github.com/carousell/Orion/utils/listenerutils
//go:generate godoc2ghmd -ex -file=spanutils/README.md github.com/carousell/Orion/utils/spanutils
//go:generate godoc2ghmd -ex -file=worker/README.md github.com/carousell/Orion/utils/worker
//go:generate godoc2ghmd -ex -file=options/README.md github.com/carousell/Orion/utils/options
//go:generate godoc2ghmd -ex -file=pubsub/README.md github.com/carousell/Orion/utils/pubsub
//go:generate godoc2ghmd -ex -file=log/README.md github.com/carousell/Orion/utils/log
67 changes: 0 additions & 67 deletions utils/executor/README.md

This file was deleted.

127 changes: 0 additions & 127 deletions utils/executor/executor.go

This file was deleted.

Loading

0 comments on commit 6eb9a3d

Please sign in to comment.