~netlandish/gobwebs

857e7b75384bae6c074518e4a5b08f46c6e7a201 — Peter Sanchez 2 years ago d49bd21
Removing custom GQueue as dowork accepted our patch adding Name() to Queue
4 files changed, 9 insertions(+), 25 deletions(-)

M go.mod
M go.sum
D server/queue.go
M server/server.go
M go.mod => go.mod +1 -1
@@ 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

M go.sum => go.sum +2 -0
@@ 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=

D server/queue.go => server/queue.go +0 -14
@@ 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}
}

M server/server.go => server/server.go +6 -10
@@ 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")
}