NOISSUE - Fix RE schedule (#234)

* NOISSUE - Fix RE schedule

Signed-off-by: Dusan Borovcanin <borovcanindusan1@gmail.com>

* Add domain to the scheduled message

Signed-off-by: Dusan Borovcanin <borovcanindusan1@gmail.com>

* Remove debug log

Signed-off-by: Dusan Borovcanin <borovcanindusan1@gmail.com>

---------

Signed-off-by: Dusan Borovcanin <borovcanindusan1@gmail.com>
This commit is contained in:
Dušan Borovčanin
2025-06-30 13:28:37 +02:00
committed by GitHub
parent f569c8a4fe
commit bf5e18acb4
13 changed files with 71 additions and 41 deletions
+16 -10
View File
@@ -20,6 +20,7 @@ type Recurring uint
const (
None Recurring = iota
Hourly
Daily
Weekly
Monthly
@@ -27,6 +28,8 @@ const (
func (rt Recurring) String() string {
switch rt {
case Hourly:
return "hourly"
case Daily:
return "daily"
case Weekly:
@@ -49,6 +52,8 @@ func (rt *Recurring) UnmarshalJSON(data []byte) error {
}
switch s {
case "hourly":
*rt = Hourly
case "daily":
*rt = Daily
case "weekly":
@@ -64,14 +69,14 @@ func (rt *Recurring) UnmarshalJSON(data []byte) error {
}
type Schedule struct {
StartDateTime *time.Time `json:"start_datetime"` // When the schedule becomes active
Time time.Time `json:"time"` // Specific time for the rule to run
Recurring Recurring `json:"recurring"` // None, Daily, Weekly, Monthly
RecurringPeriod uint `json:"recurring_period"` // Controls how many intervals to skip between executions: 1 = every interval, 2 = every second interval, etc.
StartDateTime time.Time `json:"start_datetime,omitempty"` // When the schedule becomes active
Time time.Time `json:"time,omitempty"` // Specific time for the rule to run
Recurring Recurring `json:"recurring,omitempty"` // None, Daily, Weekly, Monthly
RecurringPeriod uint `json:"recurring_period,omitempty"` // Controls how many intervals to skip between executions: 1 = every interval, 2 = every second interval, etc.
}
func (s Schedule) Validate() error {
if s.StartDateTime != nil {
if !s.StartDateTime.IsZero() {
now := time.Now().UTC()
if s.StartDateTime.Before(now) {
return ErrStartDateTimeInPast
@@ -90,7 +95,7 @@ func (s Schedule) MarshalJSON() ([]byte, error) {
Time: s.Time.Format(time.RFC3339),
Alias: (*Alias)(&s),
}
if s.StartDateTime != nil {
if !s.StartDateTime.IsZero() {
formatted := s.StartDateTime.Format(time.RFC3339)
jTimes.StartDateTime = &formatted
}
@@ -101,8 +106,8 @@ func (s Schedule) MarshalJSON() ([]byte, error) {
func (s *Schedule) UnmarshalJSON(data []byte) error {
type Alias Schedule
temp := struct {
StartDateTime string `json:"start_datetime"`
Time string `json:"time"`
StartDateTime string `json:"start_datetime,omitempty"`
Time string `json:"time,omitempty"`
*Alias
}{
Alias: (*Alias)(s),
@@ -111,13 +116,12 @@ func (s *Schedule) UnmarshalJSON(data []byte) error {
return err
}
s.StartDateTime = nil
if temp.StartDateTime != "" {
startDateTime, err := time.Parse(time.RFC3339, temp.StartDateTime)
if err != nil {
return err
}
s.StartDateTime = &startDateTime
s.StartDateTime = startDateTime
}
if temp.Time != "" {
parsedTime, err := time.Parse(time.RFC3339, temp.Time)
@@ -131,6 +135,8 @@ func (s *Schedule) UnmarshalJSON(data []byte) error {
func (s Schedule) NextDue() time.Time {
switch s.Recurring {
case Hourly:
return s.Time.Add(time.Hour * time.Duration(s.RecurringPeriod))
case Daily:
return s.Time.AddDate(0, 0, int(s.RecurringPeriod))
case Weekly: