Documentation ¶
Index ¶
- type ActiveCalculator
- func (act *ActiveCalculator) Active() bool
- func (act *ActiveCalculator) Changed() bool
- func (act *ActiveCalculator) Done()
- func (act *ActiveCalculator) Init() *ActiveCalculator
- func (act *ActiveCalculator) Process(t int64) int64
- func (act *ActiveCalculator) SetSpan(start, end time.Time)
- func (act *ActiveCalculator) StartUnix() (start int64)
- type NextFunc
- type OverrideCalculator
- type ResolvedRotation
- type ResolvedRule
- type RulesCalculator
- type ScheduleOnCallUser
- type ServiceOnCallUser
- type Shift
- type SingleRuleCalculator
- type Startable
- type Store
- func (s *Store) HistoryBySchedule(ctx context.Context, scheduleID string, start, end time.Time) ([]Shift, error)
- func (s *Store) OnCallUsersBySchedule(ctx context.Context, scheduleID string) ([]ScheduleOnCallUser, error)
- func (s *Store) OnCallUsersByService(ctx context.Context, serviceID string) ([]ServiceOnCallUser, error)
- type SubIterator
- type TemporaryScheduleCalculator
- type TimeIterator
- func (iter *TimeIterator) Close() error
- func (iter *TimeIterator) End() time.Time
- func (t *TimeIterator) NewActiveCalculator() *ActiveCalculator
- func (t *TimeIterator) NewOverrideCalculator(overrides []override.UserOverride) *OverrideCalculator
- func (t *TimeIterator) NewRulesCalculator(loc *time.Location, rules []ResolvedRule) *RulesCalculator
- func (t *TimeIterator) NewSingleRuleCalculator(loc *time.Location, rule ResolvedRule) *SingleRuleCalculator
- func (t *TimeIterator) NewTemporaryScheduleCalculator(tempScheds []schedule.TemporarySchedule) *TemporaryScheduleCalculator
- func (t *TimeIterator) NewUserCalculator() *UserCalculator
- func (iter *TimeIterator) Next() bool
- func (iter *TimeIterator) Register(sub SubIterator)
- func (iter *TimeIterator) Start() time.Time
- func (iter *TimeIterator) Step() time.Duration
- func (iter *TimeIterator) Unix() int64
- type UserCalculator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ActiveCalculator ¶ added in v0.27.0
type ActiveCalculator struct { *TimeIterator // contains filtered or unexported fields }
ActiveCalculator will calculate if the current timestamp is within a span.
func (*ActiveCalculator) Active ¶ added in v0.27.0
func (act *ActiveCalculator) Active() bool
Active will return true if the current timestamp is within a span.
func (*ActiveCalculator) Changed ¶ added in v0.27.0
func (act *ActiveCalculator) Changed() bool
Changed will return true if the current tick changed the Active() state.
func (*ActiveCalculator) Done ¶ added in v0.27.0
func (act *ActiveCalculator) Done()
Done implements the SubIterator.Done method.
func (*ActiveCalculator) Init ¶ added in v0.27.0
func (act *ActiveCalculator) Init() *ActiveCalculator
Init should be called after all SetSpan calls have been completed and before Next().
func (*ActiveCalculator) Process ¶ added in v0.27.0
func (act *ActiveCalculator) Process(t int64) int64
Process implements the SubIterator.Process method.
func (*ActiveCalculator) SetSpan ¶ added in v0.27.0
func (act *ActiveCalculator) SetSpan(start, end time.Time)
SetSpan is used to set an active span.
Care should be taken so that there is no overlap between spans, and no start time should equal any end time for non-sequential calls.
func (*ActiveCalculator) StartUnix ¶ added in v0.27.0
func (act *ActiveCalculator) StartUnix() (start int64)
type NextFunc ¶ added in v0.27.0
NextFunc can be used as a SubIterator.
type OverrideCalculator ¶ added in v0.27.0
type OverrideCalculator struct { *TimeIterator // contains filtered or unexported fields }
OverrideCalculator allows mapping a set of active users against the current set of active overrides.
func (*OverrideCalculator) Done ¶ added in v0.27.0
func (oCalc *OverrideCalculator) Done()
Done implements the SubIterator.Done method.
func (*OverrideCalculator) MapUsers ¶ added in v0.27.0
func (oCalc *OverrideCalculator) MapUsers(userIDs []string) []string
MapUsers will return a new slice of userIDs, taking into account any active overrides.
It is only valid until the following Next() call and should not be modified.
func (*OverrideCalculator) Process ¶ added in v0.27.0
func (oCalc *OverrideCalculator) Process(int64) int64
Process implements the SubIterator.Process method.
type ResolvedRotation ¶ added in v0.27.0
type ResolvedRule ¶ added in v0.27.0
type ResolvedRule struct { rule.Rule Rotation *ResolvedRotation }
type RulesCalculator ¶ added in v0.27.0
type RulesCalculator struct { *TimeIterator // contains filtered or unexported fields }
RulesCalculator provides a single interface for calculating active users of a set of ResolvedRules.
func (*RulesCalculator) ActiveUsers ¶ added in v0.27.0
func (rCalc *RulesCalculator) ActiveUsers() []string
ActiveUsers returns the current set of active users for the current timestamp. It is only valid until the following Next() call and should not be modified.
func (*RulesCalculator) Changed ¶ added in v0.27.0
func (rCalc *RulesCalculator) Changed() bool
Changed will return true if there has been any change this tick.
func (*RulesCalculator) Done ¶ added in v0.27.0
func (rCalc *RulesCalculator) Done()
Done implements the SubIterator.Done method.
func (*RulesCalculator) Process ¶ added in v0.27.0
func (rCalc *RulesCalculator) Process(int64) int64
Process implements the SubIterator.Process method.
type ScheduleOnCallUser ¶ added in v0.28.0
ScheduleOnCallUser represents a currently on-call user for a schedule.
type ServiceOnCallUser ¶
type ServiceOnCallUser struct { StepNumber int `json:"step_number"` UserID string `json:"user_id"` UserName string `json:"user_name"` }
ServiceOnCallUser represents a currently on-call user for a service.
type Shift ¶
type Shift struct { UserID string `json:"user_id"` Start time.Time `json:"start_time"` End time.Time `json:"end_time"` Truncated bool `json:"truncated"` }
A Shift represents a duration a user is on-call. If truncated is true, then the End time does not represent the time the user stopped being on call, instead it indicates they were still on-call at that time.
type SingleRuleCalculator ¶ added in v0.27.0
type SingleRuleCalculator struct { *TimeIterator // contains filtered or unexported fields }
SingleRuleCalculator will calculate the currently active user.
func (*SingleRuleCalculator) ActiveUser ¶ added in v0.27.0
func (rCalc *SingleRuleCalculator) ActiveUser() string
ActiveUser returns the currently active UserID or an empty string.
func (*SingleRuleCalculator) Changed ¶ added in v0.27.0
func (rCalc *SingleRuleCalculator) Changed() bool
Changed will return true if the ActiveUser has changed this tick.
func (*SingleRuleCalculator) Done ¶ added in v0.27.0
func (rCalc *SingleRuleCalculator) Done()
Done implements the SubIterator.Done method.
func (*SingleRuleCalculator) Process ¶ added in v0.27.0
func (rCalc *SingleRuleCalculator) Process(int64) int64
Process implements the SubIterator.Process method.
type Startable ¶ added in v0.27.0
type Startable interface { // StartUnix should return the earliest start time for this SubIterator. If it is unknown 0 should be returned. StartUnix() int64 }
Startable is a SubIterator method that allows reporting an alternate start timestamp that may extend beyond the parent TimeIterator.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store allows retrieving and calculating on-call information.
func NewStore ¶ added in v0.30.0
func NewStore(ctx context.Context, db *sql.DB, ruleStore *rule.Store, schedStore *schedule.Store) (*Store, error)
NewStore will create a new DB, preparing required statements using the provided context.
func (*Store) HistoryBySchedule ¶
func (s *Store) HistoryBySchedule(ctx context.Context, scheduleID string, start, end time.Time) ([]Shift, error)
HistoryBySchedule will return the list of shifts that overlap the start and end time for the given schedule.
func (*Store) OnCallUsersBySchedule ¶ added in v0.28.0
func (*Store) OnCallUsersByService ¶
func (s *Store) OnCallUsersByService(ctx context.Context, serviceID string) ([]ServiceOnCallUser, error)
OnCallUsersByService will return the current set of users who are on-call for the given service.
type SubIterator ¶ added in v0.27.0
type SubIterator interface { // Process will be called with each timestamp that needs processing. Each call will be sequential, but // it may not be called for each step. // // Process should return the value of the next required timestamp if it is known otherwise 0. // If the iterator has no more events to process -1 can be returned to signal complete. // // The value returned by Process must be -1, 0, or greater than t. Process(t int64) int64 // Done will be called when the iterator is no longer needed. Done() }
A SubIterator can be added to a TimeIterator via the Register method.
type TemporaryScheduleCalculator ¶ added in v0.27.0
type TemporaryScheduleCalculator struct { *TimeIterator // contains filtered or unexported fields }
TemporaryScheduleCalculator will calculate active state and active users for a set of TemporarySchedules.
func (*TemporaryScheduleCalculator) Active ¶ added in v0.27.0
func (fg *TemporaryScheduleCalculator) Active() bool
Active will return true if a TemporarySchedule is currently active.
func (*TemporaryScheduleCalculator) ActiveUsers ¶ added in v0.27.0
func (fg *TemporaryScheduleCalculator) ActiveUsers() []string
ActiveUsers will return the current set of ActiveUsers. It is only valid if `Active()` is true.
It is only valid if `Active()` is true and until the following Next() call. It should not be modified.
type TimeIterator ¶ added in v0.27.0
type TimeIterator struct {
// contains filtered or unexported fields
}
TimeIterator will iterate between start and end at a particular step interval.
func NewTimeIterator ¶ added in v0.27.0
func NewTimeIterator(start, end time.Time, step time.Duration) *TimeIterator
NewTimeIterator will create a new TimeIterator with the given configuration.
func (*TimeIterator) Close ¶ added in v0.27.0
func (iter *TimeIterator) Close() error
Close should be called when the iterator is no longer needed.
func (*TimeIterator) End ¶ added in v0.27.0
func (iter *TimeIterator) End() time.Time
End will return the end time of the TimeIterator.
func (*TimeIterator) NewActiveCalculator ¶ added in v0.27.0
func (t *TimeIterator) NewActiveCalculator() *ActiveCalculator
NewActiveCalculator will create a new ActiveCalculator bound to the TimeIterator.
func (*TimeIterator) NewOverrideCalculator ¶ added in v0.27.0
func (t *TimeIterator) NewOverrideCalculator(overrides []override.UserOverride) *OverrideCalculator
NewOverrideCalculator will create a new OverrideCalculator bound to the TimeIterator.
func (*TimeIterator) NewRulesCalculator ¶ added in v0.27.0
func (t *TimeIterator) NewRulesCalculator(loc *time.Location, rules []ResolvedRule) *RulesCalculator
NewRulesCalculator will create a new RulesCalculator bound to the TimeIterator.
func (*TimeIterator) NewSingleRuleCalculator ¶ added in v0.27.0
func (t *TimeIterator) NewSingleRuleCalculator(loc *time.Location, rule ResolvedRule) *SingleRuleCalculator
NewSingleRuleCalculator will create a new SingleRuleCalculator bound to the TimeIterator.
func (*TimeIterator) NewTemporaryScheduleCalculator ¶ added in v0.27.0
func (t *TimeIterator) NewTemporaryScheduleCalculator(tempScheds []schedule.TemporarySchedule) *TemporaryScheduleCalculator
NewTemporaryScheduleCalculator will create a new TemporaryScheduleCalculator bound to the TimeIterator.
func (*TimeIterator) NewUserCalculator ¶ added in v0.27.0
func (t *TimeIterator) NewUserCalculator() *UserCalculator
NewUserCalculator will create a new UserCalculator bound to the TimeIterator.
func (*TimeIterator) Next ¶ added in v0.27.0
func (iter *TimeIterator) Next() bool
Next will return true until iteration completes.
func (*TimeIterator) Register ¶ added in v0.27.0
func (iter *TimeIterator) Register(sub SubIterator)
Register adds a new sub Iterator.
func (*TimeIterator) Start ¶ added in v0.27.0
func (iter *TimeIterator) Start() time.Time
Start will return start time of the TimeIterator.
func (*TimeIterator) Step ¶ added in v0.27.0
func (iter *TimeIterator) Step() time.Duration
Step will return the iterators step value.
func (*TimeIterator) Unix ¶ added in v0.27.0
func (iter *TimeIterator) Unix() int64
Unix will return the current unix timestamp (seconds).
type UserCalculator ¶ added in v0.27.0
type UserCalculator struct { *TimeIterator // contains filtered or unexported fields }
UserCalculator will calculate a set of active users for a set of time spans.
func (*UserCalculator) ActiveUsers ¶ added in v0.27.0
func (u *UserCalculator) ActiveUsers() []string
ActiveUsers returns the current set of active users for the current timestamp.
It is only valid until the following Next() call and should not be modified.
func (*UserCalculator) Changed ¶ added in v0.27.0
func (u *UserCalculator) Changed() bool
Changed will return true if there has been any change this tick.
func (*UserCalculator) Done ¶ added in v0.27.0
func (u *UserCalculator) Done()
Done implements the SubIterator.Done method.
func (*UserCalculator) Init ¶ added in v0.27.0
func (u *UserCalculator) Init() *UserCalculator
Init should be called after all SetSpan values have been provided.
func (*UserCalculator) Process ¶ added in v0.27.0
func (u *UserCalculator) Process(int64) int64
Process implements the SubIterator.Process method.
func (*UserCalculator) SetSpan ¶ added in v0.27.0
func (u *UserCalculator) SetSpan(start, end time.Time, id string)
SetSpan is used to set a start & end time for the given user ID.
Care should be taken so that there is no overlap between spans of the same id, and no start time should equal any end time for the same id.