Commit fb23a285 authored by ale's avatar ale

Ensure the scheduler is initialized at agent startup

parent 1670308a
......@@ -27,17 +27,24 @@ func NewAgent(ctx context.Context, configMgr *ConfigManager, ms MetadataStore) (
}
// Create a Scheduler and tell the configMgr to reload its
// configuration too.
// configuration too. Don't forget to call the initialization
// function f() right now, since configMgr has already loaded
// a config when we start (even though this may result in f()
// being called twice, if the unbuffered notify channel in
// Notify hasn't been read yet).
sched := jobs.NewScheduler()
configMgr.Notify(func() {
f := func() {
schedule, err := makeSchedule(ctx, mgr, configMgr.getSourceSpecs(), configMgr.getSeed())
if err != nil {
log.Printf("error updating scheduler: %v", err)
}
if schedule != nil {
log.Printf("scheduler updated")
sched.SetSchedule(schedule)
}
})
}
configMgr.Notify(f)
f()
return &Agent{
mgr: mgr,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment