feat(manager): make check status from flink batch

This commit is contained in:
2024-12-07 01:09:25 +03:30
parent d1a715deea
commit 2c25323e62
12 changed files with 109 additions and 41 deletions

View File

@@ -1,33 +1,32 @@
package managed_job
import (
"errors"
"time"
"gitea.com/logicamp/lc"
"go.uber.org/zap"
)
func (job *ManagedJob) startCycle() {
ticker := time.NewTicker(5 * time.Second)
quit := make(chan struct{})
// func (job *ManagedJob) startCycle() {
// ticker := time.NewTicker(5 * time.Second)
// quit := make(chan struct{})
// load job state from db
job.loadState()
go func() {
for {
select {
case <-ticker.C:
job.cycle()
case <-quit:
ticker.Stop()
return
}
}
}()
}
// // load job state from db
// job.loadState()
// go func() {
// for {
// select {
// case <-ticker.C:
// job.cycle()
// case <-quit:
// ticker.Stop()
// return
// }
// }
// }()
// }
func (job *ManagedJob) cycle() {
func (job *ManagedJob) Cycle() {
lc.Logger.Debug("[managed-job] [new] check cycle", zap.String("jobKey", string(job.def.UID)))
// Init job
@@ -47,20 +46,15 @@ func (job *ManagedJob) cycle() {
job.crd.SetJobStatus(job.def.UID, string(job.state.Status))
// Check for set running or error state
if job.state.Status == JobStatusCreating || job.state.Status == JobStatusFailing {
/* if job.state.Status == JobStatusCreating || job.state.Status == JobStatusFailing {
err := job.checkStatus()
if errors.Is(err, ErrNoJobId) {
job.state = nil
}
return
}
} */
if job.state.Status == JobStatusRunning {
err := job.checkStatus()
if errors.Is(err, ErrNoJobId) {
job.state = nil
}
lc.Logger.Debug("savepoint interval", zap.Any("savepoint duration", job.def.Spec.SavepointInterval))
if (job.def.Spec.SavepointInterval.Duration != 0) && ((job.state.LastSavepointDate == nil) || time.Now().Add(-job.def.Spec.SavepointInterval.Duration).After(*job.state.LastSavepointDate)) {
if job.state.SavepointTriggerId == nil {
job.createSavepoint()

View File

@@ -24,7 +24,7 @@ func NewManagedJob(client *api.Client, db *buntdb.DB, def v1alpha1.FlinkJob, crd
db: db,
crd: crd,
}
job.startCycle()
//job.startCycle()
return job
}

View File

@@ -40,7 +40,13 @@ func (job *ManagedJob) run() error {
}
lc.Logger.Debug("[main] after run jar", zap.Any("run-jar-resp", runJarResp))
job.updateState(jobState{JobId: &runJarResp.JobId, Status: JobStatusCreating})
if job.state == nil {
job.state = &jobState{}
}
job.state.JobId = &runJarResp.JobId
job.state.Status = JobStatusCreating
job.updateState(*job.state)
//job.updateState(jobState{JobId: &runJarResp.JobId, Status: JobStatusCreating})
return err
}

View File

@@ -57,7 +57,15 @@ func (job *ManagedJob) removeSavepointTriggerId() {
job.updateState(*job.state)
}
func (job *ManagedJob) setStatus(status JobStatus) {
func (job *ManagedJob) SetStatus(status JobStatus) {
job.state.Status = status
job.updateState(*job.state)
}
func (job *ManagedJob) GetJobId() *string {
if job.state != nil && job.state.JobId != nil {
return job.state.JobId
} else {
return nil
}
}

View File

@@ -24,6 +24,6 @@ func (job *ManagedJob) checkStatus() error {
return err
}
//lc.Logger.Debug("[managed-job] [status]", zap.Any("status-resp", statusResp))
job.setStatus(JobStatus(statusResp.State))
job.SetStatus(JobStatus(statusResp.State))
return err
}