Skip to content

Commit 9cfba8a

Browse files
committed
fix: remove jobs from schedeuler not exisitng anymore as label fixes #76
1 parent fa0e79c commit 9cfba8a

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

cli/config.go

+49
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,27 @@ func (c *Config) buildSchedulerMiddlewares(sh *core.Scheduler) {
134134
}
135135

136136
func (c *Config) dockerLabelsUpdate(labels map[string]map[string]string) {
137+
// log start of func
138+
c.logger.Debugf("dockerLabelsUpdate started")
139+
137140
// Get the current labels
138141
var parsedLabelConfig Config
139142
parsedLabelConfig.buildFromDockerLabels(labels)
143+
c.logger.Debugf("dockerLabelsUpdate labels: %v", labels)
144+
145+
var hasIterated bool
140146

141147
// Calculate the delta execJobs
148+
hasIterated = false
142149
for name, j := range c.ExecJobs {
150+
hasIterated = true
151+
c.logger.Debugf("checking exec job %s for changes", name)
152+
found := false
143153
for newJobsName, newJob := range parsedLabelConfig.ExecJobs {
154+
c.logger.Debugf("checking exec job %s vs %s", name, newJobsName)
144155
// Check if the schedule has changed
145156
if name == newJobsName {
157+
found = true
146158
// There is a slight race condition were a job can be canceled / restarted with different params
147159
// so, lets take care of it by simply restarting
148160
// For the hash to work properly, we must fill the fields before calling it
@@ -161,10 +173,23 @@ func (c *Config) dockerLabelsUpdate(labels map[string]map[string]string) {
161173
break
162174
}
163175
}
176+
if !found {
177+
// Remove from the scheduler
178+
c.sh.RemoveJob(j)
179+
// Remove the job from the ExecJobs map
180+
delete(c.ExecJobs, name)
181+
c.logger.Debugf("removing exec job %s", name)
182+
}
183+
}
184+
if !hasIterated {
185+
c.logger.Debugf("no exec jobs to update")
164186
}
165187

166188
// Check for aditions
189+
hasIterated = false
167190
for newJobsName, newJob := range parsedLabelConfig.ExecJobs {
191+
hasIterated = true
192+
c.logger.Debugf("checking exec job %s if new", newJobsName)
168193
found := false
169194
for name := range c.ExecJobs {
170195
if name == newJobsName {
@@ -181,11 +206,19 @@ func (c *Config) dockerLabelsUpdate(labels map[string]map[string]string) {
181206
c.ExecJobs[newJobsName] = newJob
182207
}
183208
}
209+
if !hasIterated {
210+
c.logger.Debugf("no new exec jobs")
211+
}
184212

213+
hasIterated = false
185214
for name, j := range c.RunJobs {
215+
hasIterated = true
216+
c.logger.Debugf("checking run job %s for changes", name)
217+
found := false
186218
for newJobsName, newJob := range parsedLabelConfig.RunJobs {
187219
// Check if the schedule has changed
188220
if name == newJobsName {
221+
found = true
189222
// There is a slight race condition were a job can be canceled / restarted with different params
190223
// so, lets take care of it by simply restarting
191224
// For the hash to work properly, we must fill the fields before calling it
@@ -204,10 +237,23 @@ func (c *Config) dockerLabelsUpdate(labels map[string]map[string]string) {
204237
break
205238
}
206239
}
240+
if !found {
241+
// Remove from the scheduler
242+
c.sh.RemoveJob(j)
243+
// Remove the job from the RunJobs map
244+
delete(c.RunJobs, name)
245+
c.logger.Debugf("removing run job %s", name)
246+
}
247+
}
248+
if !hasIterated {
249+
c.logger.Debugf("no run jobs to update")
207250
}
208251

209252
// Check for aditions
253+
hasIterated = false
210254
for newJobsName, newJob := range parsedLabelConfig.RunJobs {
255+
hasIterated = true
256+
c.logger.Debugf("checking run job %s if new", newJobsName)
211257
found := false
212258
for name := range c.RunJobs {
213259
if name == newJobsName {
@@ -224,6 +270,9 @@ func (c *Config) dockerLabelsUpdate(labels map[string]map[string]string) {
224270
c.RunJobs[newJobsName] = newJob
225271
}
226272
}
273+
if !hasIterated {
274+
c.logger.Debugf("no new run jobs")
275+
}
227276
}
228277

229278
// ExecJobConfig contains all configuration params needed to build a ExecJob

0 commit comments

Comments
 (0)