43 lines
761 B
Go

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