feat(eda): capture schedule firings on a reserved source for bindings
This commit is contained in:
9 files changed
+170
-1
No files matched your search
@@ -36,6 +36,9 @@ func ValidatePath(path string) error {
|
||||
if path == "" || len(path) > MaxPathLen || path == "." || path == ".." {
|
||||
return ErrInvalidPath
|
||||
}
|
||||
if path == SchedulePath {
|
||||
return ErrReservedPath
|
||||
}
|
||||
for i := range len(path) {
|
||||
if !unreserved(path[i]) {
|
||||
return ErrInvalidPath
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package source
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"time"
|
||||
)
|
||||
|
||||
// SchedulePath is the source a schedule's firing is captured on. It is
|
||||
// reserved: no endpoint receives on it and no operator source may take it, so
|
||||
// only the scheduler writes its captures.
|
||||
const SchedulePath = "schedule"
|
||||
|
||||
// ScheduleFiredType and ScheduleFiredMapping name the built-in event type and
|
||||
// mapping that identify and map every capture on SchedulePath. A schedule
|
||||
// trigger is a binding on SchedulePath using ScheduleFiredMapping, filtered to
|
||||
// one schedule_id.
|
||||
const (
|
||||
ScheduleFiredType = "schedule-fired"
|
||||
ScheduleFiredMapping = "schedule-fired"
|
||||
)
|
||||
|
||||
// ScheduleFired is one firing of a schedule: the payload of its capture.
|
||||
type ScheduleFired struct {
|
||||
ScheduleID string `json:"schedule_id"`
|
||||
Name string `json:"name"`
|
||||
ScheduledFor time.Time `json:"scheduled_for"`
|
||||
FiredAt time.Time `json:"fired_at"`
|
||||
}
|
||||
|
||||
// Delivery names the firing of one slot. A retried firing of the slot shares
|
||||
// it, so a binding starts at most one task per slot.
|
||||
func (f ScheduleFired) Delivery() string {
|
||||
return f.ScheduleID + "@" + f.ScheduledFor.UTC().Format(time.RFC3339Nano)
|
||||
}
|
||||
|
||||
// Body is the capture payload.
|
||||
func (f ScheduleFired) Body() ([]byte, error) {
|
||||
f.ScheduledFor, f.FiredAt = f.ScheduledFor.UTC(), f.FiredAt.UTC()
|
||||
return json.Marshal(f)
|
||||
}
|
||||
@@ -31,6 +31,8 @@ var (
|
||||
ErrInvalidPath = errors.New("source: path must be 1-128 URL-safe characters (A-Z a-z 0-9 - . _ ~), not a dot segment")
|
||||
// ErrInvalidHeader refuses a delivery header that is not an HTTP field name.
|
||||
ErrInvalidHeader = errors.New("source: delivery header must be an HTTP header name")
|
||||
// ErrReservedPath refuses a path the scheduler captures on.
|
||||
ErrReservedPath = errors.New("source: path is reserved")
|
||||
// ErrSigningTransition refuses an approval with no pending request.
|
||||
ErrSigningTransition = errors.New("source: signing transition rejected")
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user