File tree Expand file tree Collapse file tree 1 file changed +7
-3
lines changed Expand file tree Collapse file tree 1 file changed +7
-3
lines changed Original file line number Diff line number Diff line change 4
4
"context"
5
5
"errors"
6
6
"sync"
7
+ "sync/atomic"
7
8
"time"
8
9
9
10
"github.com/appleboy/queue"
@@ -25,6 +26,7 @@ type Worker struct {
25
26
stop chan struct {}
26
27
logger queue.Logger
27
28
stopOnce sync.Once
29
+ stopFlag int32
28
30
}
29
31
30
32
// BeforeRun run script before start worker
@@ -102,6 +104,10 @@ func (s *Worker) Run() error {
102
104
103
105
// Shutdown worker
104
106
func (s * Worker ) Shutdown () error {
107
+ if ! atomic .CompareAndSwapInt32 (& s .stopFlag , 0 , 1 ) {
108
+ return queue .ErrQueueShutdown
109
+ }
110
+
105
111
s .stopOnce .Do (func () {
106
112
close (s .stop )
107
113
close (s .taskQueue )
@@ -121,10 +127,8 @@ func (s *Worker) Usage() int {
121
127
122
128
// Queue send notification to queue
123
129
func (s * Worker ) Queue (job queue.QueuedMessage ) error {
124
- select {
125
- case <- s .stop :
130
+ if atomic .LoadInt32 (& s .stopFlag ) == 1 {
126
131
return queue .ErrQueueShutdown
127
- default :
128
132
}
129
133
130
134
select {
You can’t perform that action at this time.
0 commit comments