mirror of
https://gitee.com/goploy/goploy.git
synced 2024-12-03 12:39:44 +08:00
38 lines
631 B
Go
38 lines
631 B
Go
// Copyright 2022 The Goploy Authors. All rights reserved.
|
|
// Use of this source code is governed by a GPLv3-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package task
|
|
|
|
import (
|
|
"context"
|
|
"sync/atomic"
|
|
"time"
|
|
)
|
|
|
|
var counter int32
|
|
|
|
var stop = make(chan struct{})
|
|
|
|
func Init() {
|
|
startMonitorTask()
|
|
startProjectTask()
|
|
startServerMonitorTask()
|
|
startDeployTask()
|
|
}
|
|
|
|
func Shutdown(ctx context.Context) error {
|
|
close(stop)
|
|
ticker := time.NewTicker(10 * time.Millisecond)
|
|
for {
|
|
select {
|
|
case <-ctx.Done():
|
|
return ctx.Err()
|
|
case <-ticker.C:
|
|
if atomic.LoadInt32(&counter) == 0 {
|
|
return nil
|
|
}
|
|
}
|
|
}
|
|
}
|