feat: add manager
This commit is contained in:
42
internal/manager/manager.go
Normal file
42
internal/manager/manager.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package manager
|
||||
|
||||
import (
|
||||
"flink-kube-operator/internal/crd"
|
||||
"flink-kube-operator/internal/managed_job"
|
||||
"time"
|
||||
|
||||
api "github.com/logi-camp/go-flink-client"
|
||||
"github.com/tidwall/buntdb"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
)
|
||||
|
||||
var managedJobs = map[types.UID]managed_job.ManagedJob{}
|
||||
|
||||
func Setup(client *api.Client, db *buntdb.DB) {
|
||||
ticker := time.NewTicker(5 * time.Second)
|
||||
quit := make(chan struct{})
|
||||
|
||||
go func() {
|
||||
for {
|
||||
select {
|
||||
case <-ticker.C:
|
||||
cycle(client, db)
|
||||
case <-quit:
|
||||
ticker.Stop()
|
||||
return
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
func cycle(client *api.Client, db *buntdb.DB) {
|
||||
for _, uid := range crd.GetAllJobKeys() {
|
||||
job := crd.GetJob(uid)
|
||||
_, ok := managedJobs[uid]
|
||||
if ok {
|
||||
|
||||
} else {
|
||||
managed_job.NewManagedJob(client, db, job)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user