Skip to content

Commit 70ccc5b

Browse files
authored
fix: gracefully stop the queue (#25)
1 parent 4c7c7ae commit 70ccc5b

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

.github/workflows/lint.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
runs-on: ubuntu-latest
1414
strategy:
1515
matrix:
16-
go-version: ["oldstable", "stable"]
16+
go-version: ["stable"]
1717
env:
1818
VERBOSE: 1
1919

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/bxcodec/goqueue
22

3-
go 1.22
3+
go 1.23
44

55
require (
66
github.com/google/uuid v1.6.0

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)