Skip to content
Snippets Groups Projects
Verified Commit 51d60bd0 authored by Volker Schukai's avatar Volker Schukai :alien:
Browse files

feat: new manager function saveJob

parent 268f02f0
No related branches found
No related tags found
No related merge requests found
......@@ -306,6 +306,25 @@ func (m *Manager) removeJobInternal(id JobID) error {
}
// SaveJob saves a job to the database
func (m *Manager) SaveJob(job GenericJob) error {
if m == nil {
return ErrManagerNotInitialized
}
m.mu.Lock()
defer m.mu.Unlock()
if m.jobSyncer != nil {
return m.jobSyncer.SaveJob(job)
}
return nil
}
// UpdateJob updates a job in the database
func (m *Manager) UpdateJob(job GenericJob) error {
if m == nil {
......@@ -690,7 +709,6 @@ func (m *Manager) handleJobEvents() {
err := m.queue.Enqueue(job)
if err != nil && !errors.Is(err, ErrJobAlreadyExists) {
Error("Error while queueing job", "error", err)
}
case JobReady:
......@@ -733,9 +751,7 @@ func (m *Manager) handleJobEvents() {
eventBus := m.GetEventBus()
eventBus.Publish(JobFinished, nextJob)
}
}
}
}
......
......@@ -146,10 +146,6 @@ func (sp *SchedulerPersistence) UnmarshalYAML(unmarshal func(interface{}) error)
type Alias SchedulerPersistence
aux := &struct {
*Alias `yaml:",inline"`
//TimeString *string `yaml:"time,omitempty"`
//IntervalString *string `yaml:"interval,omitempty"`
//DelayString *string `yaml:"delay,omitempty"`
//EventFlagsString *string `yaml:"eventFlags,omitempty"`
}{
Alias: (*Alias)(sp),
}
......@@ -161,7 +157,6 @@ func (sp *SchedulerPersistence) UnmarshalYAML(unmarshal func(interface{}) error)
if err != nil {
return err
}
sp.Time = &t
}
......@@ -206,93 +201,3 @@ func (sp *SchedulerPersistence) UnmarshalYAML(unmarshal func(interface{}) error)
}
return nil
}
//type scheduleImportStruct struct {
// Time *string `yaml:"time,omitempty" json:"time,omitempty"`
// Interval *string `yaml:"interval,omitempty" json:"interval,omitempty"`
// Delay *string `yaml:"delay,omitempty" json:"delay,omitempty"`
// EventFlags *string `yaml:"eventFlags,omitempty" json:"eventFlags,omitempty"`
//
// Type string `yaml:"type" json:"type"`
// Spec string `yaml:"spec,omitempty" json:"spec,omitempty"`
// Event string `yaml:"event,omitempty" json:"event,omitempty"`
// Executed bool `yaml:"executed,omitempty" json:"executed,omitempty"`
// Path string `yaml:"path,omitempty" json:"path,omitempty"`
//}
//
//func (sp *SchedulerPersistence) parseAndAssignFields(aux scheduleImportStruct) error {
//
// sp.Type = aux.Type
// sp.Spec = aux.Spec
// sp.Event = EventName(aux.Event)
// sp.Executed = aux.Executed
// sp.Path = aux.Path
//
// if aux.Time != nil && *aux.Time != "" {
// var t time.Time
// var err error
// for _, format := range SupportedTimeFormats {
// t, err = time.Parse(format, *aux.Time)
// if err == nil {
// break
// }
// }
// if err != nil {
// return err
// }
// sp.Time = &t
// }
//
// if aux.Interval != nil && *aux.Interval != "" {
// d, err := time.ParseDuration(*aux.Interval)
// if err != nil {
// return err
// }
// sp.Interval = d
// }
//
// if aux.Delay != nil && *aux.Delay != "" {
// d, err := time.ParseDuration(*aux.Delay)
// if err != nil {
// return err
// }
// sp.Delay = d
// }
//
// if aux.EventFlags != nil && *aux.EventFlags != "" {
// sp.EventFlags = fsnotify.Op(0)
// for _, flag := range strings.Split(*aux.EventFlags, "|") {
// switch flag {
// case "Create":
// sp.EventFlags |= fsnotify.Create
// case "Write":
// sp.EventFlags |= fsnotify.Write
// case "Remove":
// sp.EventFlags |= fsnotify.Remove
// case "Rename":
// sp.EventFlags |= fsnotify.Rename
// case "Chmod":
// sp.EventFlags |= fsnotify.Chmod
// }
// }
// }
//
// return nil
//}
//// UnmarshalJSON implements the json.Unmarshaler interface
//func (sp *SchedulerPersistence) UnmarshalJSON(data []byte) error {
// var aux scheduleImportStruct
// if err := json.Unmarshal(data, &aux); err != nil {
// return err
// }
// return sp.parseAndAssignFields(aux)
//}
//
//func (sp *SchedulerPersistence) UnmarshalYAML(unmarshal func(interface{}) error) error {
// var aux scheduleImportStruct
// if err := unmarshal(&aux); err != nil {
// return err
// }
// return sp.parseAndAssignFields(aux)
//}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment