NOISSUE - Add callout in Rule Engine Service (#277)

* add callout to re

Signed-off-by: Arvindh <arvindh91@gmail.com>

* add callout to re

Signed-off-by: Arvindh <arvindh91@gmail.com>

* add callout to re

Signed-off-by: Arvindh <arvindh91@gmail.com>

* add rule events

Signed-off-by: Arvindh <arvindh91@gmail.com>

* add rule events

Signed-off-by: Arvindh <arvindh91@gmail.com>

* add rule events

Signed-off-by: Arvindh <arvindh91@gmail.com>

* remove lints

Signed-off-by: Arvindh <arvindh91@gmail.com>

* remove lints

Signed-off-by: Arvindh <arvindh91@gmail.com>

* remove decoders

Signed-off-by: Arvindh <arvindh91@gmail.com>

* remove lints

Signed-off-by: Arvindh <arvindh91@gmail.com>

* remove lints

Signed-off-by: Arvindh <arvindh91@gmail.com>

* replace interface{} with any

Signed-off-by: Arvindh <arvindh91@gmail.com>

* optimization of event

Signed-off-by: Arvindh <arvindh91@gmail.com>

* remove lints

Signed-off-by: Arvindh <arvindh91@gmail.com>

* align code

Signed-off-by: Arvindh <arvindh91@gmail.com>

---------

Signed-off-by: Arvindh <arvindh91@gmail.com>
This commit is contained in:
Arvindh
2025-08-26 12:47:27 +05:30
committed by GitHub
parent 3413564148
commit ffc7a1ff78
9 changed files with 682 additions and 20 deletions
+33 -10
View File
@@ -10,6 +10,14 @@ import (
"github.com/absmach/supermq/pkg/errors"
)
const (
noneType = "none"
hourlyType = "hourly"
dailyType = "daily"
weeklyType = "weekly"
monthlyType = "monthly"
)
var (
ErrInvalidRecurringType = errors.New("invalid recurring type")
ErrStartDateTimeInPast = errors.New("start_datetime must be greater than or equal to current time")
@@ -29,15 +37,15 @@ const (
func (rt Recurring) String() string {
switch rt {
case Hourly:
return "hourly"
return hourlyType
case Daily:
return "daily"
return dailyType
case Weekly:
return "weekly"
return weeklyType
case Monthly:
return "monthly"
return monthlyType
default:
return "none"
return noneType
}
}
@@ -52,15 +60,15 @@ func (rt *Recurring) UnmarshalJSON(data []byte) error {
}
switch s {
case "hourly":
case hourlyType:
*rt = Hourly
case "daily":
case dailyType:
*rt = Daily
case "weekly":
case weeklyType:
*rt = Weekly
case "monthly":
case monthlyType:
*rt = Monthly
case "none":
case noneType:
*rt = None
default:
return ErrInvalidRecurringType
@@ -147,3 +155,18 @@ func (s Schedule) NextDue() time.Time {
return time.Time{}
}
}
// EventEncode converts a schedule.Schedule struct to map[string]any.
func (s Schedule) EventEncode() map[string]any {
m := map[string]any{
"recurring": s.Recurring.String(),
"recurring_period": s.RecurringPeriod,
}
if !s.StartDateTime.IsZero() {
m["start_datetime"] = s.StartDateTime.Format(time.RFC3339)
}
if !s.Time.IsZero() {
m["time"] = s.Time.Format(time.RFC3339)
}
return m
}