Skip to content

Commit 2f872ab

Browse files
committed
fix: gracefully stop the queue
1 parent 4c7c7ae commit 2f872ab

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

queueservice.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,18 @@ func (qs *QueueService) Start(ctx context.Context) (err error) {
6565
// Stop stops the queue service by stopping the consumer and closing the publisher.
6666
// It returns an error if there was an issue stopping the consumer or closing the publisher.
6767
func (qs *QueueService) Stop(ctx context.Context) error {
68-
if qs.consumer == nil {
69-
return errors.New("consumer is not defined")
70-
}
71-
err := qs.consumer.Stop(ctx)
72-
if err != nil {
73-
return err
68+
if qs.consumer != nil {
69+
err := qs.consumer.Stop(ctx)
70+
if err != nil {
71+
return err
72+
}
7473
}
7574

76-
err = qs.publisher.Close(ctx)
77-
if err != nil {
78-
return err
75+
if qs.publisher != nil {
76+
err := qs.publisher.Close(ctx)
77+
if err != nil {
78+
return err
79+
}
7980
}
8081
return nil
8182
}

0 commit comments

Comments
 (0)