Skip to content

Commit b5cdd86

Browse files
authored
fix scheduler and provide get-update-by-extender method (#501)
Signed-off-by: Mikhail Scherba <mikhail.scherba@flant.com>
1 parent c937de3 commit b5cdd86

2 files changed

Lines changed: 18 additions & 8 deletions

File tree

pkg/module_manager/module_manager.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,11 +475,16 @@ func (mm *ModuleManager) GetEnabledModuleNames() []string {
475475
return mm.moduleScheduler.GetEnabledModuleNames()
476476
}
477477

478-
// IsModuleEnabled ...
478+
// IsModuleEnabled returns current state of the module according to the scheduler
479479
func (mm *ModuleManager) IsModuleEnabled(moduleName string) bool {
480480
return mm.moduleScheduler.IsModuleEnabled(moduleName)
481481
}
482482

483+
// GetUpdatedByExtender returns the name of the extender that determined the module's state
484+
func (mm *ModuleManager) GetUpdatedByExtender(moduleName string) (string, error) {
485+
return mm.moduleScheduler.GetUpdatedByExtender(moduleName)
486+
}
487+
483488
func (mm *ModuleManager) AddExtender(ex extenders.Extender) error {
484489
return mm.moduleScheduler.AddExtender(ex)
485490
}

pkg/module_manager/scheduler/scheduler.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -351,12 +351,19 @@ func moduleSortFunc(m1, m2 string) bool {
351351
return m1 < m2
352352
}
353353

354+
func (s *Scheduler) GetUpdatedByExtender(moduleName string) (string, error) {
355+
vertex, err := s.dag.Vertex(moduleName)
356+
if err != nil {
357+
return "", err
358+
}
359+
return vertex.GetUpdatedBy(), err
360+
}
361+
354362
func (s *Scheduler) IsModuleEnabled(moduleName string) bool {
355363
vertex, err := s.dag.Vertex(moduleName)
356364
if err != nil {
357365
return false
358366
}
359-
360367
return vertex.GetState()
361368
}
362369

@@ -482,18 +489,16 @@ outerCycle:
482489
if e.ext.IsTerminator() {
483490
// if disabled - terminate filtering
484491
if !*moduleStatus {
492+
// if so far is enabled OR there are ahead other extenders that could enable the module,
493+
// mark the module as disabled by the terminator
485494
if vBuf[moduleName].enabled || e.filterAhead {
486495
vBuf[moduleName].enabled = *moduleStatus
487496
vBuf[moduleName].updatedBy = string(e.ext.Name())
488497
}
489498
break
490499
}
491-
492-
// if enabled and there are some other filtering extenders ahead - continue filtering
493-
if e.filterAhead {
494-
continue
495-
}
496-
break
500+
// continue checking extenders
501+
continue
497502
}
498503
vBuf[moduleName].enabled = *moduleStatus
499504
vBuf[moduleName].updatedBy = string(e.ext.Name())

0 commit comments

Comments
 (0)