goploy/cmd/server/task/task.go
2022-11-23 16:49:55 +08:00

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
}
}
}
}