Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • master
  • v1.0.0
  • v1.0.1
  • v1.1.0
  • v1.10.0
  • v1.10.1
  • v1.10.2
  • v1.11.0
  • v1.12.0
  • v1.12.1
  • v1.12.2
  • v1.12.3
  • v1.12.4
  • v1.12.5
  • v1.12.6
  • v1.12.7
  • v1.12.8
  • v1.13.0
  • v1.13.1
  • v1.13.2
  • v1.14.0
  • v1.15.0
  • v1.15.1
  • v1.15.10
  • v1.15.11
  • v1.15.12
  • v1.15.13
  • v1.15.14
  • v1.15.15
  • v1.15.16
  • v1.15.17
  • v1.15.2
  • v1.15.3
  • v1.15.4
  • v1.15.5
  • v1.15.6
  • v1.15.7
  • v1.15.8
  • v1.15.9
  • v1.16.0
  • v1.16.1
  • v1.17.0
  • v1.18.0
  • v1.18.1
  • v1.18.2
  • v1.19.0
  • v1.19.1
  • v1.19.2
  • v1.19.3
  • v1.19.4
  • v1.2.0
  • v1.20.0
  • v1.20.1
  • v1.20.2
  • v1.20.3
  • v1.21.0
  • v1.21.1
  • v1.22.0
  • v1.23.0
  • v1.23.1
  • v1.23.2
  • v1.3.0
  • v1.3.1
  • v1.3.2
  • v1.4.0
  • v1.5.0
  • v1.5.1
  • v1.6.0
  • v1.6.1
  • v1.7.0
  • v1.7.1
  • v1.7.2
  • v1.7.3
  • v1.8.0
  • v1.8.1
  • v1.9.0
76 results

Target

Select target project
  • oss/libraries/go/services/job-queues
1 result
Select Git revision
  • master
  • v1.0.0
  • v1.0.1
  • v1.1.0
  • v1.10.0
  • v1.10.1
  • v1.10.2
  • v1.11.0
  • v1.12.0
  • v1.12.1
  • v1.12.2
  • v1.12.3
  • v1.12.4
  • v1.12.5
  • v1.12.6
  • v1.12.7
  • v1.12.8
  • v1.13.0
  • v1.13.1
  • v1.13.2
  • v1.14.0
  • v1.15.0
  • v1.15.1
  • v1.15.10
  • v1.15.11
  • v1.15.12
  • v1.15.13
  • v1.15.14
  • v1.15.15
  • v1.15.16
  • v1.15.17
  • v1.15.2
  • v1.15.3
  • v1.15.4
  • v1.15.5
  • v1.15.6
  • v1.15.7
  • v1.15.8
  • v1.15.9
  • v1.16.0
  • v1.16.1
  • v1.17.0
  • v1.18.0
  • v1.18.1
  • v1.18.2
  • v1.19.0
  • v1.19.1
  • v1.19.2
  • v1.19.3
  • v1.19.4
  • v1.2.0
  • v1.20.0
  • v1.20.1
  • v1.20.2
  • v1.20.3
  • v1.21.0
  • v1.21.1
  • v1.22.0
  • v1.23.0
  • v1.23.1
  • v1.23.2
  • v1.3.0
  • v1.3.1
  • v1.3.2
  • v1.4.0
  • v1.5.0
  • v1.5.1
  • v1.6.0
  • v1.6.1
  • v1.7.0
  • v1.7.1
  • v1.7.2
  • v1.7.3
  • v1.8.0
  • v1.8.1
  • v1.9.0
76 results
Show changes
Commits on Source (1)
...@@ -105,6 +105,25 @@ func (j *JobPersistence) UnmarshalJSON(data []byte) error { ...@@ -105,6 +105,25 @@ func (j *JobPersistence) UnmarshalJSON(data []byte) error {
return nil return nil
} }
func parseDateFormats(value string) (time.Time, error) {
return parseMultipleDateFormats(value, []string{
time.RFC3339, time.RFC3339Nano,
"2006-01-02T15:04:05",
"2006-01-02T15:04:05.999999999",
"2006-01-02T15:04:05Z07:00",
"2006-01-02T15:04:05",
"2006-01-02T15:04",
"2006-01-02T15",
"2006-01-02 15:04:05",
"2006-01-02 15:04:05.999999999",
"2006-01-02 15:04:05Z07:00",
"2006-01-02 15:04:05",
"2006-01-02 15:04",
"2006-01-02 15",
"2006-01-02",
})
}
func parseMultipleDateFormats(value string, formats []string) (time.Time, error) { func parseMultipleDateFormats(value string, formats []string) (time.Time, error) {
var t time.Time var t time.Time
var err error var err error
...@@ -356,11 +375,11 @@ func CreateJobAndSchedulerFromPersistence(jobImport JobPersistence, manager *Man ...@@ -356,11 +375,11 @@ func CreateJobAndSchedulerFromPersistence(jobImport JobPersistence, manager *Man
switch sType { switch sType {
case "interval": case "interval":
if jobImport.Scheduler.Interval == 0 { if *jobImport.Scheduler.Interval == 0 {
return nil, nil, fmt.Errorf("%w: interval is 0", ErrSchedulerMisconfiguration) return nil, nil, fmt.Errorf("%w: interval is 0", ErrSchedulerMisconfiguration)
} }
scheduler = &IntervalScheduler{Interval: jobImport.Scheduler.Interval} scheduler = &IntervalScheduler{Interval: *jobImport.Scheduler.Interval}
case "cron": case "cron":
...@@ -385,11 +404,11 @@ func CreateJobAndSchedulerFromPersistence(jobImport JobPersistence, manager *Man ...@@ -385,11 +404,11 @@ func CreateJobAndSchedulerFromPersistence(jobImport JobPersistence, manager *Man
case "delay": case "delay":
if jobImport.Scheduler.Delay == 0 { if *jobImport.Scheduler.Delay == 0 {
return nil, nil, fmt.Errorf("%w: delay is 0", ErrSchedulerMisconfiguration) return nil, nil, fmt.Errorf("%w: delay is 0", ErrSchedulerMisconfiguration)
} }
scheduler = &DelayScheduler{Delay: jobImport.Scheduler.Delay} scheduler = &DelayScheduler{Delay: *jobImport.Scheduler.Delay}
case "event": case "event":
......
...@@ -17,6 +17,7 @@ func TestCreateJobAndSchedulerFromInput(t *testing.T) { ...@@ -17,6 +17,7 @@ func TestCreateJobAndSchedulerFromInput(t *testing.T) {
time10s := 10 * time.Second time10s := 10 * time.Second
time2s := 5 * time.Minute time2s := 5 * time.Minute
time1m := 1 * time.Minute
tests := []struct { tests := []struct {
name string name string
...@@ -39,7 +40,7 @@ func TestCreateJobAndSchedulerFromInput(t *testing.T) { ...@@ -39,7 +40,7 @@ func TestCreateJobAndSchedulerFromInput(t *testing.T) {
}, },
Scheduler: SchedulerPersistence{ Scheduler: SchedulerPersistence{
Type: "Interval", Type: "Interval",
Interval: 1 * time.Minute, Interval: &time1m,
}, },
}, },
wantJob: GenericJob(&Job[ShellResult]{ /* Initialization */ }), wantJob: GenericJob(&Job[ShellResult]{ /* Initialization */ }),
......
...@@ -97,6 +97,6 @@ func (s *DelayScheduler) JobExists(id JobID) bool { ...@@ -97,6 +97,6 @@ func (s *DelayScheduler) JobExists(id JobID) bool {
func (s *DelayScheduler) GetPersistence() SchedulerPersistence { func (s *DelayScheduler) GetPersistence() SchedulerPersistence {
return SchedulerPersistence{ return SchedulerPersistence{
Type: s.GetType(), Type: s.GetType(),
Delay: s.Delay, Delay: &s.Delay,
} }
} }
...@@ -105,6 +105,6 @@ func (s *IntervalScheduler) JobExists(id JobID) bool { ...@@ -105,6 +105,6 @@ func (s *IntervalScheduler) JobExists(id JobID) bool {
func (s *IntervalScheduler) GetPersistence() SchedulerPersistence { func (s *IntervalScheduler) GetPersistence() SchedulerPersistence {
return SchedulerPersistence{ return SchedulerPersistence{
Type: s.GetType(), Type: s.GetType(),
Interval: s.Interval, Interval: &s.Interval,
} }
} }
...@@ -28,7 +28,7 @@ interval: "1h30m" ...@@ -28,7 +28,7 @@ interval: "1h30m"
assert.Equal(t, expectedTime, *sp.Time, "the time should be parsed correctly") assert.Equal(t, expectedTime, *sp.Time, "the time should be parsed correctly")
expectedInterval, _ := time.ParseDuration("1h30m") expectedInterval, _ := time.ParseDuration("1h30m")
assert.Equal(t, expectedInterval, sp.Interval, "the interval should be parsed correctly") assert.Equal(t, &expectedInterval, sp.Interval, "the interval should be parsed correctly")
} }
// TestUnmarshalJSON tests the UnmarshalJSON method // TestUnmarshalJSON tests the UnmarshalJSON method
...@@ -56,5 +56,5 @@ func TestUnmarshalJSON(t *testing.T) { ...@@ -56,5 +56,5 @@ func TestUnmarshalJSON(t *testing.T) {
// Verify that the Delay field is correctly parsed // Verify that the Delay field is correctly parsed
expectedInterval, _ := time.ParseDuration("1h30m") expectedInterval, _ := time.ParseDuration("1h30m")
assert.Equal(t, expectedInterval, sp.Interval, "Interval should be correctly parsed") assert.Equal(t, &expectedInterval, sp.Interval, "Interval should be correctly parsed")
} }
...@@ -23,10 +23,15 @@ type Scheduler interface { ...@@ -23,10 +23,15 @@ type Scheduler interface {
} }
type SchedulerPersistence struct { type SchedulerPersistence struct {
Time *time.Time `yaml:"time,omitempty" json:"time,omitempty" gorm:"column:time"` Time *time.Time `yaml:"-" json:"-" gorm:"column:time"`
Interval time.Duration `yaml:"interval,omitempty" json:"interval,omitempty" gorm:"column:interval"` Interval *time.Duration `yaml:"-" json:"-" gorm:"column:interval"`
Delay time.Duration `yaml:"delay,omitempty" json:"delay,omitempty" gorm:"column:delay"` Delay *time.Duration `yaml:"-" json:"-" gorm:"column:delay"`
EventFlags fsnotify.Op `yaml:"eventFlags,omitempty" json:"eventFlags,omitempty" gorm:"column:eventFlags"` EventFlags fsnotify.Op `yaml:"-" json:"-" gorm:"column:eventFlags"`
TimeString *string `yaml:"time,omitempty" json:"time,omitempty" gorm:"-"`
IntervalString *string `yaml:"interval,omitempty" json:"interval,omitempty" gorm:"-"`
DelayString *string `yaml:"delay,omitempty" json:"delay,omitempty" gorm:"-"`
EventFlagsString *string `yaml:"eventFlags,omitempty" json:"eventFlags,omitempty" gorm:"-"`
Type string `yaml:"type" json:"type" gorm:"column:type"` Type string `yaml:"type" json:"type" gorm:"column:type"`
Spec string `yaml:"spec,omitempty" json:"spec,omitempty" gorm:"column:spec"` Spec string `yaml:"spec,omitempty" json:"spec,omitempty" gorm:"column:spec"`
...@@ -35,61 +40,155 @@ type SchedulerPersistence struct { ...@@ -35,61 +40,155 @@ type SchedulerPersistence struct {
Path string `yaml:"path,omitempty" json:"path,omitempty" gorm:"column:path"` Path string `yaml:"path,omitempty" json:"path,omitempty" gorm:"column:path"`
} }
type scheduleImportStruct struct { func formatEventFlags(flags fsnotify.Op) string {
Time *string `yaml:"time,omitempty" json:"time,omitempty"` var flagStrings []string
Interval *string `yaml:"interval,omitempty" json:"interval,omitempty"` if flags&fsnotify.Create != 0 {
Delay *string `yaml:"delay,omitempty" json:"delay,omitempty"` flagStrings = append(flagStrings, "Create")
EventFlags *string `yaml:"eventFlags,omitempty" json:"eventFlags,omitempty"` }
if flags&fsnotify.Write != 0 {
Type string `yaml:"type" json:"type"` flagStrings = append(flagStrings, "Write")
Spec string `yaml:"spec,omitempty" json:"spec,omitempty"` }
Event string `yaml:"event,omitempty" json:"event,omitempty"` if flags&fsnotify.Remove != 0 {
Executed bool `yaml:"executed,omitempty" json:"executed,omitempty"` flagStrings = append(flagStrings, "Remove")
Path string `yaml:"path,omitempty" json:"path,omitempty"` }
if flags&fsnotify.Rename != 0 {
flagStrings = append(flagStrings, "Rename")
}
if flags&fsnotify.Chmod != 0 {
flagStrings = append(flagStrings, "Chmod")
}
return strings.Join(flagStrings, "|")
}
func (j *SchedulerPersistence) MarshalJSON() ([]byte, error) {
type Alias SchedulerPersistence
return json.Marshal(&struct {
*Alias
TimeString string `json:"time,omitempty"`
IntervalString string `json:"interval,omitempty"`
DelayString string `json:"delay,omitempty"`
EventFlagsString string `json:"eventFlags,omitempty"`
}{
Alias: (*Alias)(j),
TimeString: formatTime(j.Time),
IntervalString: formatDuration(j.Interval),
DelayString: formatDuration(j.Delay),
EventFlagsString: formatEventFlags(j.EventFlags),
})
} }
func (sp *SchedulerPersistence) parseAndAssignFields(aux scheduleImportStruct) error { func (j *SchedulerPersistence) UnmarshalJSON(data []byte) error {
type Alias SchedulerPersistence
sp.Type = aux.Type aux := &struct {
sp.Spec = aux.Spec *Alias
sp.Event = EventName(aux.Event) TimeString *string `json:"time,omitempty"`
sp.Executed = aux.Executed IntervalString *string `json:"interval,omitempty"`
sp.Path = aux.Path DelayString *string `json:"delay,omitempty"`
EventFlagsString *string `json:"eventFlags,omitempty"`
if aux.Time != nil && *aux.Time != "" { }{
var t time.Time Alias: (*Alias)(j),
var err error }
for _, format := range SupportedTimeFormats { if err := json.Unmarshal(data, aux); err != nil {
t, err = time.Parse(format, *aux.Time) return err
if err == nil { }
break if aux.TimeString != nil && *aux.TimeString != "" {
t, err := parseDateFormats(*aux.TimeString)
if err != nil {
return err
}
j.Time = &t
}
if aux.DelayString != nil && *aux.DelayString != "" {
d, err := time.ParseDuration(*aux.DelayString)
if err != nil {
return err
}
j.Delay = &d
}
if aux.IntervalString != nil && *aux.IntervalString != "" {
d, err := time.ParseDuration(*aux.IntervalString)
if err != nil {
return err
}
j.Interval = &d
}
if aux.DelayString != nil && *aux.DelayString != "" {
d, err := time.ParseDuration(*aux.DelayString)
if err != nil {
return err
}
j.Delay = &d
}
if aux.EventFlagsString != nil && *aux.EventFlagsString != "" {
j.EventFlags = fsnotify.Op(0)
for _, flag := range strings.Split(*aux.EventFlagsString, "|") {
switch flag {
case "Create":
j.EventFlags |= fsnotify.Create
case "Write":
j.EventFlags |= fsnotify.Write
case "Remove":
j.EventFlags |= fsnotify.Remove
case "Rename":
j.EventFlags |= fsnotify.Rename
case "Chmod":
j.EventFlags |= fsnotify.Chmod
} }
} }
}
return nil
}
func (sp *SchedulerPersistence) UnmarshalYAML(unmarshal func(interface{}) error) 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),
}
if err := unmarshal(aux); err != nil {
return err
}
if aux.TimeString != nil && *aux.TimeString != "" {
t, err := parseDateFormats(*aux.TimeString)
if err != nil { if err != nil {
return err return err
} }
sp.Time = &t sp.Time = &t
} }
if aux.Interval != nil && *aux.Interval != "" { if aux.DelayString != nil && *aux.DelayString != "" {
d, err := time.ParseDuration(*aux.Interval) d, err := time.ParseDuration(*aux.DelayString)
if err != nil { if err != nil {
return err return err
} }
sp.Interval = d sp.Delay = &d
} }
if aux.IntervalString != nil && *aux.IntervalString != "" {
if aux.Delay != nil && *aux.Delay != "" { d, err := time.ParseDuration(*aux.IntervalString)
d, err := time.ParseDuration(*aux.Delay)
if err != nil { if err != nil {
return err return err
} }
sp.Delay = d sp.Interval = &d
} }
if aux.DelayString != nil && *aux.DelayString != "" {
if aux.EventFlags != nil && *aux.EventFlags != "" { d, err := time.ParseDuration(*aux.DelayString)
if err != nil {
return err
}
sp.Delay = &d
}
if aux.EventFlagsString != nil && *aux.EventFlagsString != "" {
sp.EventFlags = fsnotify.Op(0) sp.EventFlags = fsnotify.Op(0)
for _, flag := range strings.Split(*aux.EventFlags, "|") { for _, flag := range strings.Split(*aux.EventFlagsString, "|") {
switch flag { switch flag {
case "Create": case "Create":
sp.EventFlags |= fsnotify.Create sp.EventFlags |= fsnotify.Create
...@@ -101,26 +200,99 @@ func (sp *SchedulerPersistence) parseAndAssignFields(aux scheduleImportStruct) e ...@@ -101,26 +200,99 @@ func (sp *SchedulerPersistence) parseAndAssignFields(aux scheduleImportStruct) e
sp.EventFlags |= fsnotify.Rename sp.EventFlags |= fsnotify.Rename
case "Chmod": case "Chmod":
sp.EventFlags |= fsnotify.Chmod sp.EventFlags |= fsnotify.Chmod
} }
} }
} }
return nil return nil
} }
// UnmarshalJSON implements the json.Unmarshaler interface //type scheduleImportStruct struct {
func (sp *SchedulerPersistence) UnmarshalJSON(data []byte) error { // Time *string `yaml:"time,omitempty" json:"time,omitempty"`
var aux scheduleImportStruct // Interval *string `yaml:"interval,omitempty" json:"interval,omitempty"`
if err := json.Unmarshal(data, &aux); err != nil { // Delay *string `yaml:"delay,omitempty" json:"delay,omitempty"`
return err // EventFlags *string `yaml:"eventFlags,omitempty" json:"eventFlags,omitempty"`
} //
return sp.parseAndAssignFields(aux) // 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
//}
func (sp *SchedulerPersistence) UnmarshalYAML(unmarshal func(interface{}) error) error { //// UnmarshalJSON implements the json.Unmarshaler interface
var aux scheduleImportStruct //func (sp *SchedulerPersistence) UnmarshalJSON(data []byte) error {
if err := unmarshal(&aux); err != nil { // var aux scheduleImportStruct
return err // if err := json.Unmarshal(data, &aux); err != nil {
} // return err
return sp.parseAndAssignFields(aux) // }
} // 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)
//}
...@@ -429,7 +429,7 @@ time: "2023-12-15T12:00:00Z" ...@@ -429,7 +429,7 @@ time: "2023-12-15T12:00:00Z"
expectedTime, _ := time.Parse(time.RFC3339, "2023-12-15T12:00:00Z") expectedTime, _ := time.Parse(time.RFC3339, "2023-12-15T12:00:00Z")
assert.Equal(t, "interval", sp.Type, "Type should be unmarshalled correctly") assert.Equal(t, "interval", sp.Type, "Type should be unmarshalled correctly")
assert.Equal(t, expectedInterval, sp.Interval, "Interval should be unmarshalled correctly") assert.Equal(t, &expectedInterval, sp.Interval, "Interval should be unmarshalled correctly")
assert.Equal(t, &expectedTime, sp.Time, "Time should be unmarshalled correctly") assert.Equal(t, &expectedTime, sp.Time, "Time should be unmarshalled correctly")
} }
...@@ -446,5 +446,5 @@ interval: "1m1s" ...@@ -446,5 +446,5 @@ interval: "1m1s"
expectedInterval, _ := time.ParseDuration("1m1s") expectedInterval, _ := time.ParseDuration("1m1s")
assert.Equal(t, "Interval", sp.Type, "Type should be unmarshalled correctly") assert.Equal(t, "Interval", sp.Type, "Type should be unmarshalled correctly")
assert.Equal(t, expectedInterval, sp.Interval, "Interval should be unmarshalled correctly") assert.Equal(t, &expectedInterval, sp.Interval, "Interval should be unmarshalled correctly")
} }