chore: update worker interface (#592)

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi Wu
2021-07-16 19:26:19 +08:00
committed by GitHub
parent 73ff554b19
commit 41c61f11c4
6 changed files with 30 additions and 22 deletions

View File

@@ -4,23 +4,29 @@ import (
"errors"
"github.com/appleboy/gorush/gorush"
"github.com/appleboy/gorush/queue"
)
var _ queue.Worker = (*Worker)(nil)
// Worker for simple queue using channel
type Worker struct {
queueNotification chan gorush.PushNotification
}
// Run start the worker
func (s *Worker) Run(_ chan struct{}) {
func (s *Worker) Run(_ chan struct{}) error {
for notification := range s.queueNotification {
gorush.SendNotification(notification)
}
return nil
}
// Stop worker
func (s *Worker) Stop() {
// Shutdown worker
func (s *Worker) Shutdown() error {
close(s.queueNotification)
return nil
}
// Capacity for channel
@@ -33,8 +39,8 @@ func (s *Worker) Usage() int {
return len(s.queueNotification)
}
// Enqueue send notification to queue
func (s *Worker) Enqueue(job interface{}) error {
// Queue send notification to queue
func (s *Worker) Queue(job interface{}) error {
select {
case s.queueNotification <- job.(gorush.PushNotification):
return nil