@@ -126,10 +126,12 @@ type Worker struct {
126126 ZoneID string
127127 Token string
128128
129- lastPending time.Time
130- lastCollect time.Time
131- lastStatus time.Time
132- statusRunning uint32
129+ lastPending time.Time
130+ pendingRunning uint32
131+ lastCollect time.Time
132+ collectRunning uint32
133+ lastStatus time.Time
134+ statusRunning uint32
133135}
134136
135137func (w * Worker ) Run () {
@@ -160,24 +162,43 @@ func (w *Worker) Run() {
160162 }
161163 }
162164
163- if time .Since (w .lastPending ) >= 10 * time .Second {
165+ var running uint32
166+
167+ running = atomic .LoadUint32 (& w .pendingRunning )
168+ if running == 0 && time .Since (w .lastPending ) >= 10 * time .Second {
164169 w .lastPending = time .Now ()
165- w .runStatusVerify ()
170+ go func () {
171+ atomic .StoreUint32 (& w .pendingRunning , 1 )
172+ defer atomic .StoreUint32 (& w .pendingRunning , 0 )
173+
174+ w .runStatusVerify ()
175+ }()
166176 }
167177
168- if time .Since (w .lastCollect ) >= time .Hour {
178+ running = atomic .LoadUint32 (& w .collectRunning )
179+ if running == 0 && time .Since (w .lastCollect ) >= time .Hour {
169180 w .lastCollect = time .Now ()
170181 go func () {
182+ atomic .StoreUint32 (& w .collectRunning , 1 )
183+ defer atomic .StoreUint32 (& w .collectRunning , 0 )
184+
171185 w .runCollect (ctx )
172186 w .summaryProjectUsage (ctx )
173187 }()
174188 }
175189
176- running : = atomic .LoadUint32 (& w .statusRunning )
190+ running = atomic .LoadUint32 (& w .statusRunning )
177191 if running == 0 && time .Since (w .lastStatus ) > 6 * time .Hour {
178192 w .lastStatus = time .Now ()
179- go w .runStatus ()
193+ go func () {
194+ atomic .StoreUint32 (& w .statusRunning , 1 )
195+ defer atomic .StoreUint32 (& w .statusRunning , 0 )
196+
197+ w .runStatus ()
198+ }()
180199 }
200+
201+ time .Sleep (3 * time .Second )
181202}
182203
183204func (w * Worker ) runStatusVerify () {
@@ -205,9 +226,6 @@ func (w *Worker) runStatusVerify() {
205226}
206227
207228func (w * Worker ) runStatus () {
208- atomic .StoreUint32 (& w .statusRunning , 1 )
209- defer atomic .StoreUint32 (& w .statusRunning , 0 )
210-
211229 defer slog .Info ("status: finished" )
212230
213231 ctx := context .Background ()
0 commit comments