From 857e7b75384bae6c074518e4a5b08f46c6e7a201 Mon Sep 17 00:00:00 2001 From: Peter Sanchez Date: Mon, 29 Aug 2022 15:19:51 -0600 Subject: [PATCH] Removing custom GQueue as dowork accepted our patch adding Name() to Queue --- go.mod | 2 +- go.sum | 2 ++ server/queue.go | 14 -------------- server/server.go | 16 ++++++---------- 4 files changed, 9 insertions(+), 25 deletions(-) delete mode 100644 server/queue.go diff --git a/go.mod b/go.mod index 60e6033..88d28a8 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module hg.code.netlandish.com/~netlandish/gobwebs go 1.18 require ( - git.sr.ht/~sircmpwn/dowork v0.0.0-20210820133136-d3970e97def3 + git.sr.ht/~sircmpwn/dowork v0.0.0-20220826210403-887bcd8841d8 github.com/alexedwards/argon2id v0.0.0-20211130144151-3585854a6387 github.com/alexedwards/scs/postgresstore v0.0.0-20211203064041-370cc303b69f github.com/alexedwards/scs/v2 v2.5.0 diff --git a/go.sum b/go.sum index b45058c..5005d7f 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,7 @@ git.sr.ht/~sircmpwn/dowork v0.0.0-20210820133136-d3970e97def3 h1:9WCv5cK67s2SiY/R4DWT/OchEsFnfYDz3lbevKxZ4QI= git.sr.ht/~sircmpwn/dowork v0.0.0-20210820133136-d3970e97def3/go.mod h1:8neHEO3503w/rNtttnR0JFpQgM/GFhaafVwvkPsFIDw= +git.sr.ht/~sircmpwn/dowork v0.0.0-20220826210403-887bcd8841d8 h1:L9G3YfLV2yTYDDudFEe9YhbHRbxBfESBpcPzZ8juwPg= +git.sr.ht/~sircmpwn/dowork v0.0.0-20220826210403-887bcd8841d8/go.mod h1:8neHEO3503w/rNtttnR0JFpQgM/GFhaafVwvkPsFIDw= github.com/Masterminds/squirrel v1.5.3 h1:YPpoceAcxuzIljlr5iWpNKaql7hLeG1KLSrhvdHpkZc= github.com/Masterminds/squirrel v1.5.3/go.mod h1:NNaOrjSoIDfDA40n7sr2tPNZRfjzjA400rg+riTZj10= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= diff --git a/server/queue.go b/server/queue.go deleted file mode 100644 index 2cfa86c..0000000 --- a/server/queue.go +++ /dev/null @@ -1,14 +0,0 @@ -package server - -import work "git.sr.ht/~sircmpwn/dowork" - -// GQueue is a dowork queue wrapper that lets you name it -type GQueue struct { - Queue *work.Queue - Name string -} - -// NewQueue returns a new GQueue instance -func NewQueue(name string) *GQueue { - return &GQueue{work.NewQueue(name), name} -} diff --git a/server/server.go b/server/server.go index ae54d15..19b44be 100644 --- a/server/server.go +++ b/server/server.go @@ -59,7 +59,7 @@ type Server struct { e *echo.Echo ai *appInfo csrfSkip []string - queues []*GQueue + queues []*work.Queue } // Context is the context passed to handlers and middlewares @@ -321,11 +321,11 @@ func (s *Server) WithMiddleware(middlewares ...echo.MiddlewareFunc) *Server { } // WithQueues add dowork task queues for this server to manage -func (s *Server) WithQueues(queues ...*GQueue) *Server { +func (s *Server) WithQueues(queues ...*work.Queue) *Server { ctx := context.Background() s.queues = append(s.queues, queues...) for _, queue := range queues { - queue.Queue.Start(ctx) + queue.Start(ctx) } return s } @@ -334,8 +334,8 @@ func (s *Server) WithQueues(queues ...*GQueue) *Server { // by queue name. func (s *Server) QueueTask(qname string, task *work.Task) error { for _, q := range s.queues { - if q.Name == qname { - return q.Queue.Enqueue(task) + if q.Name() == qname { + return q.Enqueue(task) } } return fmt.Errorf("No queue found with name '%s'", qname) @@ -411,11 +411,7 @@ func (s *Server) Shutdown() { cancel() s.e.Logger.Printf("Terminating work queues...\n") - var queues []*work.Queue - for _, q := range s.queues { - queues = append(queues, q.Queue) - } - work.Join(queues...) + work.Join(s.queues...) s.e.Logger.Printf("Shutdown completed.\n") } -- 2.45.2