MCPcopy
hub / github.com/tuna/tunasync / runSchedule

Method runSchedule

worker/worker.go:274–385  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

272}
273
274func (w *Worker) runSchedule() {
275 w.L.Lock()
276
277 mirrorList := w.fetchJobStatus()
278 unset := make(map[string]bool)
279 for name := range w.jobs {
280 unset[name] = true
281 }
282 // Fetch mirror list stored in the manager
283 // put it on the scheduled time
284 // if it's disabled, ignore it
285 for _, m := range mirrorList {
286 if job, ok := w.jobs[m.Name]; ok {
287 delete(unset, m.Name)
288 switch m.Status {
289 case Disabled:
290 job.SetState(stateDisabled)
291 continue
292 case Paused:
293 job.SetState(statePaused)
294 go job.Run(w.managerChan, w.semaphore)
295 continue
296 default:
297 job.SetState(stateNone)
298 go job.Run(w.managerChan, w.semaphore)
299 stime := m.LastUpdate.Add(job.provider.Interval())
300 logger.Debugf("Scheduling job %s @%s", job.Name(), stime.Format("2006-01-02 15:04:05"))
301 w.schedule.AddJob(stime, job)
302 }
303 }
304 }
305 // some new jobs may be added
306 // which does not exist in the
307 // manager's mirror list
308 for name := range unset {
309 job := w.jobs[name]
310 job.SetState(stateNone)
311 go job.Run(w.managerChan, w.semaphore)
312 w.schedule.AddJob(time.Now(), job)
313 }
314
315 w.L.Unlock()
316
317 schedInfo := w.schedule.GetJobs()
318 w.updateSchedInfo(schedInfo)
319
320 tick := time.NewTicker(5 * time.Second).C
321 for {
322 select {
323 case jobMsg := <-w.managerChan:
324 // got status update from job
325 w.L.Lock()
326 job, ok := w.jobs[jobMsg.name]
327 w.L.Unlock()
328 if !ok {
329 logger.Warningf("Job %s not found", jobMsg.name)
330 continue
331 }

Callers 1

RunMethod · 0.95

Calls 15

fetchJobStatusMethod · 0.95
updateSchedInfoMethod · 0.95
updateStatusMethod · 0.95
SetStateMethod · 0.80
DebugfMethod · 0.80
AddJobMethod · 0.80
GetJobsMethod · 0.80
WarningfMethod · 0.80
StateMethod · 0.80
InfofMethod · 0.80
NoticefMethod · 0.80
PopMethod · 0.80

Tested by

no test coverage detected