fix: address review comments on admin_script seeding

- Replace TOCTOU race (separate Load+Save) with atomic
  SaveJobTypeConfigIfNotExists on ConfigStore and Plugin
- Replace ineffective polling loop with single GetMaster call using
  30s context timeout, since GetMaster respects context cancellation
- Add unit tests for SaveJobTypeConfigIfNotExists (in-memory + on-disk)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Chris LuandClaude Opus 4.6 committed 2026-03-04 21:27:52 -08:00
1 parent 5432c03ba5
commit 4b2a231913
4 files changed
+146 -18

No files matched your search

+13
View File
@@ -402,6 +402,19 @@ func (r *Plugin) SaveJobTypeConfig(config *plugin_pb.PersistedJobTypeConfig) err
return nil
}
// SaveJobTypeConfigIfNotExists atomically saves config only if no config
// exists yet for the job type. Returns true if saved, false if already exists.
func (r *Plugin) SaveJobTypeConfigIfNotExists(config *plugin_pb.PersistedJobTypeConfig) (bool, error) {
saved, err := r.store.SaveJobTypeConfigIfNotExists(config)
if err != nil {
return false, err
}
if saved {
r.wakeScheduler()
}
return saved, nil
}
func (r *Plugin) LoadDescriptor(jobType string) (*plugin_pb.JobTypeDescriptor, error) {
return r.store.LoadDescriptor(jobType)
}