@@ -134,15 +134,27 @@ func (c *Config) buildSchedulerMiddlewares(sh *core.Scheduler) {
134
134
}
135
135
136
136
func (c * Config ) dockerLabelsUpdate (labels map [string ]map [string ]string ) {
137
+ // log start of func
138
+ c .logger .Debugf ("dockerLabelsUpdate started" )
139
+
137
140
// Get the current labels
138
141
var parsedLabelConfig Config
139
142
parsedLabelConfig .buildFromDockerLabels (labels )
143
+ c .logger .Debugf ("dockerLabelsUpdate labels: %v" , labels )
144
+
145
+ var hasIterated bool
140
146
141
147
// Calculate the delta execJobs
148
+ hasIterated = false
142
149
for name , j := range c .ExecJobs {
150
+ hasIterated = true
151
+ c .logger .Debugf ("checking exec job %s for changes" , name )
152
+ found := false
143
153
for newJobsName , newJob := range parsedLabelConfig .ExecJobs {
154
+ c .logger .Debugf ("checking exec job %s vs %s" , name , newJobsName )
144
155
// Check if the schedule has changed
145
156
if name == newJobsName {
157
+ found = true
146
158
// There is a slight race condition were a job can be canceled / restarted with different params
147
159
// so, lets take care of it by simply restarting
148
160
// 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) {
161
173
break
162
174
}
163
175
}
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" )
164
186
}
165
187
166
188
// Check for aditions
189
+ hasIterated = false
167
190
for newJobsName , newJob := range parsedLabelConfig .ExecJobs {
191
+ hasIterated = true
192
+ c .logger .Debugf ("checking exec job %s if new" , newJobsName )
168
193
found := false
169
194
for name := range c .ExecJobs {
170
195
if name == newJobsName {
@@ -181,11 +206,19 @@ func (c *Config) dockerLabelsUpdate(labels map[string]map[string]string) {
181
206
c .ExecJobs [newJobsName ] = newJob
182
207
}
183
208
}
209
+ if ! hasIterated {
210
+ c .logger .Debugf ("no new exec jobs" )
211
+ }
184
212
213
+ hasIterated = false
185
214
for name , j := range c .RunJobs {
215
+ hasIterated = true
216
+ c .logger .Debugf ("checking run job %s for changes" , name )
217
+ found := false
186
218
for newJobsName , newJob := range parsedLabelConfig .RunJobs {
187
219
// Check if the schedule has changed
188
220
if name == newJobsName {
221
+ found = true
189
222
// There is a slight race condition were a job can be canceled / restarted with different params
190
223
// so, lets take care of it by simply restarting
191
224
// 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) {
204
237
break
205
238
}
206
239
}
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" )
207
250
}
208
251
209
252
// Check for aditions
253
+ hasIterated = false
210
254
for newJobsName , newJob := range parsedLabelConfig .RunJobs {
255
+ hasIterated = true
256
+ c .logger .Debugf ("checking run job %s if new" , newJobsName )
211
257
found := false
212
258
for name := range c .RunJobs {
213
259
if name == newJobsName {
@@ -224,6 +270,9 @@ func (c *Config) dockerLabelsUpdate(labels map[string]map[string]string) {
224
270
c .RunJobs [newJobsName ] = newJob
225
271
}
226
272
}
273
+ if ! hasIterated {
274
+ c .logger .Debugf ("no new run jobs" )
275
+ }
227
276
}
228
277
229
278
// ExecJobConfig contains all configuration params needed to build a ExecJob
0 commit comments