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) }