schedules

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 29, 2026 License: AGPL-3.0 Imports: 32 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package schedules holds the Schedules of C-27: a Team's plans of who is On-call and when, each with a name unique in the Team, a time zone and its Rotation layers, with Overrides on top. One Schedule of a Team is its main Schedule, whose On-call is the Team's. The package computes the Shifts of the Rotation layers and the Result of a Schedule — its segments, each with the person On-call or nobody in a gap — on the business clock, skipping the people who may not be Paged. Every change is recorded in the Audit log and announced with the live hint schedule; nothing is sent to a messenger (C-27.FR-11). The package finds the gaps of the Schedules, whose Leader scan raises MusterScheduleGap (C-27.FR-7), and "On call now" (C-27.FR-9); it exports muster_schedule_info and muster_schedule_gap.

Index

Constants

View Source
const (
	ActionFeedIssued  = "ical_feed.issued"
	ActionFeedRevoked = "ical_feed.revoked"
)

The Audit log actions of the iCal feeds (C-27.FR-10), whose resource is their User.

View Source
const (
	FeedBasePath = "/ical/"
	FeedSuffix   = ".ics"
)

FeedBasePath is where the iCal feeds are served on the app listener: FeedBasePath, the token, then FeedSuffix.

View Source
const (
	ReachNoAccountLink          = "no_account_link"
	ReachBridgeNoNativeMentions = "bridge_no_native_mentions"
	ReachWebhookNoThreadReply   = "webhook_no_thread_reply"
	ReachNotInDiscussionGroup   = "not_in_discussion_group"
)

The reasons a Mention of an On-call cannot reach a Destination (ReachReason, C-27.FR-8).

View Source
const (
	ReasonViewer    = "viewer"
	ReasonDisabled  = "disabled"
	ReasonNotInTeam = "not_in_team"
)

The reasons a person may not be Paged (C-27.FR-5), which are also the kinds of their warnings.

View Source
const (
	SourceOverride      = "override"
	SourceRotationLayer = "rotation_layer"
)

The kinds of the source of a segment of the Result.

View Source
const (
	ShiftDay   = "day"
	ShiftWeek  = "week"
	ShiftHours = "hours"
)

The Shift lengths of a Rotation layer.

View Source
const (
	ActionCreated         = "schedule.created"
	ActionUpdated         = "schedule.updated"
	ActionDeleted         = "schedule.deleted"
	ActionOverrideCreated = "schedule_override.created"
	ActionOverrideUpdated = "schedule_override.updated"
	ActionOverrideDeleted = "schedule_override.deleted"
	ResourceSchedule      = "schedule"
	ResourceOverride      = "schedule_override"
	Hint                  = "schedule"
)

The Audit log actions and resource types, and the live hint, of Schedules and Overrides (C-27.FR-6, FR-13).

View Source
const (
	// GapView is schedule.gap_view, the default period of the On-call, in which next_gap and "On call now" look.
	GapView = 14 * 24 * time.Hour
	// GapAlertHorizon is schedule.gap_alert_horizon: the gap scan raises MusterScheduleGap for a gap now or one that
	// starts within it.
	GapAlertHorizon = 7 * 24 * time.Hour
	// ICalWindowBack and ICalWindowAhead are ical.window (P-81): the iCal feed reaches from 7 days back to 60 days
	// ahead.
	ICalWindowBack  = 7 * 24 * time.Hour
	ICalWindowAhead = 60 * 24 * time.Hour
	// MaxPeriod is the longest period of getScheduleOnCall: the length of ical.window, 67 days. The iCal feed reads a
	// day more, from midnight to midnight UTC (ICalSpan).
	MaxPeriod = ICalWindowBack + ICalWindowAhead
	// Reach is how far from the business clock's now a period of the On-call may start or end.
	Reach = 10 * 365 * 24 * time.Hour
	// MaxShiftSeconds is the longest Shift in hours: 28 days.
	MaxShiftSeconds = 28 * 24 * 60 * 60
	// MaxRotationLayers and MaxRotationLayerUsers are the most Rotation layers of a Schedule and people of a Rotation
	// layer.
	MaxRotationLayers     = 20
	MaxRotationLayerUsers = 100
	// OverrideGrace is how far before the business clock's now an Override may start: the time it takes to fill the
	// form.
	OverrideGrace = 5 * time.Minute
	// MaxOverrideLength is the longest Override: 31 days.
	MaxOverrideLength = 31 * 24 * time.Hour
	// MaxOverlappingOverrides is how many Overrides of a Schedule a new span may overlap, short of one more.
	MaxOverlappingOverrides = 1000
)

The settings of Schedules that bound the periods it reads.

View Source
const (
	GapAlertByDefault = "by_default"
	GapAlertOn        = "on"
	GapAlertOff       = "off"
)

The values of schedule.gap_alert: by_default is on while the Schedule is its Team's main one (C-27.FR-7).

View Source
const (
	CodeRequired      = "required"
	CodeInvalidFormat = "invalid_format"
	CodeTooLong       = "too_long"
	CodeOutOfRange    = "out_of_range"
	CodeDuplicate     = "duplicate"
	CodeUnknownID     = "unknown_id"
	CodeUnsupported   = "unsupported"
	CodeNotPageable   = "not_pageable"
)

The codes of FieldError, as the API names them.

ICalSpan is the span the feed reads: ical.window from midnight UTC of the day ICalWindowBack before the business clock's day to midnight UTC at the end of the day ICalWindowAhead after it, so a day more than MaxPeriod.

View Source
const (
	MaxNameLength = 200
)

The limits of a Schedule, in characters.

View Source
const ReferrerChain = "escalation_chain"

ReferrerChain is the kind of an Escalation chain whose steps name a Schedule.

View Source
const WarningGap = "gap"

WarningGap is the kind of the warning of a gap of the Result (C-27.FR-7).

View Source
const WarningUnreachable = "unreachable"

WarningUnreachable is the kind of the warning of a segment in which a Mention of its On-call cannot reach a Destination of their Team, or one in whose Threads a chain that Pages the Schedule writes (C-27.FR-8).

Variables

View Source
var (
	FirstStartDate = time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC)
	LastStartDate  = time.Date(2100, 12, 31, 0, 0, 0, 0, time.UTC)
)

The first and the last start date of a Rotation layer.

View Source
var (
	// ErrNotFound is a Schedule that does not exist in the Organization.
	ErrNotFound = errors.New("no such schedule")
	// ErrOverrideNotFound is an Override that the Schedule does not have.
	ErrOverrideNotFound = errors.New("no such override")
	// ErrNameTaken is a name another Schedule of the Team has, ignoring case.
	ErrNameTaken = errors.New("another schedule of the team has this name")
	// ErrVersionMismatch is an If-Match that names another version.
	ErrVersionMismatch = errors.New("the schedule or override changed since it was read")
	// ErrNotInTeam is an Override by someone who is neither in the Schedule's Team nor an Admin (not_in_team).
	ErrNotInTeam = errors.New("the caller is not in the team of the schedule")
	// ErrOverrideEnded is a change or deletion of an Override that has ended (override_ended).
	ErrOverrideEnded = errors.New("the override has ended")
	// ErrInUse is the deletion of a Schedule that an Escalation step names (schedule_in_use); InUseError names them.
	ErrInUse = errors.New("escalation steps name the schedule")
)
View Source
var ErrFeedNotFound = errors.New("no such ical feed")

ErrFeedNotFound is a token that names no iCal feed of an active User: malformed, unknown, revoked, or of a disabled or deleted User. It never says which.

View Source
var ErrFeedUserInactive = errors.New("the user of the ical feed is not active")

ErrFeedUserInactive is an issue of a feed for a User who is not active, disabled or deleted meanwhile.

View Source
var ErrFeedUserNotFound = errors.New("no such user")

ErrFeedUserNotFound is a revoke of the feed of a User who does not exist or is deleted.

View Source
var Weekdays = []string{"monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"}

Weekdays are the days of the week as the API and the CHECKs name them, Monday first.

Functions

func Calendar

func Calendar(events []Event, user, host string, stamp time.Time) []byte

Calendar writes the events of the User user (a public_id) as an iCal document whose DTSTAMP is stamp: the times in UTC, each event named "{Team} · {Schedule}", transparent — being On-call is not being busy — with the UID "{schedule public_id}-{user public_id}-{start}@{host}", which stays the same while the event starts at the same time and differs between the feeds of two Users; host is the host of MUSTER_PUBLIC_URL. The VTIMEZONE of UTC, which no time refers to, keeps a calendar without events valid: RFC 5545 asks for one component at least. Its lines end in CRLF and are folded at 75 octets.

Types

type Actor

type Actor struct {
	Kind        string
	PublicID    string
	Name        string
	Login       string
	Deactivated bool
}

Actor is who made an Override: a User or a Service account, deactivated once deleted.

type Config

type Config struct {
	OrgID    int64
	Store    Store
	Audit    *audit.Writer
	Business clock.Clock
}

Config is what a Service needs: the Organization, the Store, the Audit log writer and the business clock, which dates the rows and is the only time the On-call reads (C-27.FR-4).

type DestinationRef

type DestinationRef struct {
	ID           int64
	PublicID     string
	Name         string
	Type         string
	Health       string
	BrokenSince  *time.Time
	BrokenReason *string
}

DestinationRef names a Destination with its type and health.

type Event

type Event struct {
	Schedule   string
	Team, Name string
	Start, End time.Time
}

Event is an event of an iCal feed: a span in which the User is On-call in the Schedule, of the Team Team, named Name.

type Feed

type Feed struct {
	IssuedAt *time.Time
}

Feed is whether a User has an iCal feed: IssuedAt is when it was issued, nil without one.

type FeedQueries

type FeedQueries interface {
	ListUserSchedules(ctx context.Context, arg dbgen.ListUserSchedulesParams) ([]dbgen.ListUserSchedulesRow, error)
	ReplaceIcalFeed(ctx context.Context, arg dbgen.ReplaceIcalFeedParams) (bool, error)
	GetIcalFeed(ctx context.Context, arg dbgen.GetIcalFeedParams) (time.Time, error)
	DeleteIcalFeed(ctx context.Context, arg dbgen.DeleteIcalFeedParams) (int64, error)
	GetFeedUser(ctx context.Context, arg dbgen.GetFeedUserParams) (dbgen.GetFeedUserRow, error)
	FindIcalFeed(ctx context.Context, tokenHash []byte) (dbgen.FindIcalFeedRow, error)
	audit.Store
}

FeedQueries are the queries of the iCal feeds, with the insert of the Audit log.

type FeedStore

type FeedStore interface {
	FeedQueries
	InTx(ctx context.Context, f func(FeedQueries) error) error
	On(tx dbgen.DBTX) FeedQueries
}

FeedStore runs the queries of the iCal feeds alone, in one transaction, or in the transaction of another package.

func NewFeedStore

func NewFeedStore(pool *pgxpool.Pool) FeedStore

NewFeedStore is the FeedStore over the main pool.

type FeedUser

type FeedUser struct {
	ID       int64
	PublicID string
}

FeedUser is the User of an iCal feed.

type Feeds

type Feeds struct {
	// contains filtered or unexported fields
}

Feeds holds the personal iCal feeds of the Users of the Organization (C-27.FR-10): one per User, issued from the web session and shown once, its token (ical.token) stored only as its SHA-256 (ADR-0011).

func NewFeeds

func NewFeeds(cfg FeedsConfig) *Feeds

NewFeeds returns the Feeds of the Organization in cfg.

func (*Feeds) Calendar

func (f *Feeds) Calendar(ctx context.Context, u FeedUser) ([]byte, error)

Calendar is the iCal document of the feed of the User u (C-27.FR-10): one event per span of ical.window — from ICalWindowBack before the start of the business clock's day in UTC to the end of the day ICalWindowAhead after it — in which u is On-call in a Schedule of one of their Teams, the only Schedules in which they can be, by its Result.

func (*Feeds) Get

func (f *Feeds) Get(ctx context.Context, userID int64) (Feed, error)

Get reads whether the User userID has an iCal feed.

func (*Feeds) Issue

func (f *Feeds) Issue(ctx context.Context, r Requester, u FeedUser) (IssuedFeed, error)

Issue issues the iCal feed of the User u, replacing the one they had in the same statement, so that the previous link stops working at once, and records ical_feed.issued without the token. A User who is not active, disabled or deleted meanwhile, gets ErrFeedUserInactive and no feed.

func (*Feeds) Lookup

func (f *Feeds) Lookup(ctx context.Context, value string) (FeedUser, error)

Lookup finds the User of the iCal feed whose token is value: an active User of the Organization, else ErrFeedNotFound, with the User when the feed exists but its User is disabled or deleted.

func (*Feeds) RemoveUserFeed

func (f *Feeds) RemoveUserFeed(ctx context.Context, tx usersdb.DBTX, userID int64, userPublicID string,
	actor audit.Actor, t audit.Transport, addr netip.Addr) (func(context.Context), error)

RemoveUserFeed deletes the iCal feed of a deleted User in the transaction tx of the deletion, recorded as ical_feed.revoked by the actor of the deletion with the reason user_deleted. It is the users package's FeedRemover; it has nothing to run once tx committed.

func (*Feeds) Revoke

func (f *Feeds) Revoke(ctx context.Context, r Requester, u FeedUser) error

Revoke deletes the iCal feed of the User u, whose link stops working at once, and records ical_feed.revoked; without a feed it does nothing.

func (*Feeds) RevokeOfUser

func (f *Feeds) RevokeOfUser(ctx context.Context, r Requester, userPublicID string) error

RevokeOfUser deletes the iCal feed of the User userPublicID for an Admin, whose link stops working at once, and records ical_feed.revoked with the reason revoked_by_admin; without a feed it does nothing. An unknown or deleted User is ErrFeedUserNotFound.

type FeedsConfig

type FeedsConfig struct {
	OrgID     int64
	Store     FeedStore
	Audit     *audit.Writer
	Business  clock.Clock
	Schedules *Service
	PublicURL string
}

FeedsConfig is what Feeds need: the Organization, the Store, the Audit log writer, the business clock, which dates the feeds and places ical.window, the Schedules, whose Result the feed lists, and MUSTER_PUBLIC_URL, the base of the links.

type FieldError

type FieldError struct {
	Pointer string
	Code    string
	Detail  string
	Reason  string
}

FieldError is a field of a request that is not valid, at a JSON pointer of the request body, with a stable code of the validation-failed problem; Reason says why a person may not be Paged with not_pageable.

func (*FieldError) Error

func (e *FieldError) Error() string

type Gap

type Gap struct {
	Start, End time.Time
}

Gap is a time in which nobody is On-call in a Schedule: no Override and no Rotation layer has a Shift with a person who may be Paged (C-27.FR-5).

type GapScan

type GapScan struct {
	Store Store
	// Business is the business clock, on which the Schedules compute their On-call (C-27.FR-4).
	Business clock.Clock
	Log      *logging.Logger
	// RunbookBase is MUSTER_RUNBOOK_BASE_URL.
	RunbookBase string
	// contains filtered or unexported fields
}

GapScan is the Leader task schedule_gap_scan (C-27.FR-7): every schedule.gap_scan_interval it computes the Result of each Schedule whose gap alert is active from the business clock's now to schedule.gap_alert_horizon ahead, raises MusterScheduleGap for each with a gap now or within the horizon, and resolves it for the others, those whose gap alert is no longer active and the deleted ones. It reads the open alerts from the database, the pending raises included, and writes only what changed, so a second run writes nothing, and two runs at once write the same raise twice, which the Internal alert's fingerprint deduplicates (ADR-0007). It sets muster_schedule_gap.

func (*GapScan) Forget

func (g *GapScan) Forget()

Forget removes every muster_schedule_gap series this replica exports: it stops leading, and the next Leader exports its own.

func (*GapScan) Scan

func (g *GapScan) Scan(ctx context.Context, orgID int64) error

Scan runs the gap scan of the Organization orgID.

type InUseError

type InUseError struct {
	Referrers []Referrer
}

InUseError is ErrInUse with the objects that name the Schedule.

func (*InUseError) Error

func (e *InUseError) Error() string

func (*InUseError) Unwrap

func (e *InUseError) Unwrap() error

type Input

type Input struct {
	TeamID         string
	Name           string
	TimeZone       *string
	Main           *bool
	GapAlert       *string
	RotationLayers []RotationLayerInput
	// ManagedBy is the mark of the tool that keeps the Schedule as code (C-33.FR-11).
	ManagedBy managedby.Input
}

Input is what createSchedule and updateSchedule write. A nil TimeZone is the Organization's on a creation and keeps the stored one on an update; a nil Main is false on a creation, unless the Team has no Schedule, and keeps the stored value on an update; a nil GapAlert is by_default on a creation and keeps the stored one on an update.

type IssuedFeed

type IssuedFeed struct {
	URL      string
	IssuedAt time.Time
}

IssuedFeed is an iCal feed just issued: its link, which carries the token and is shown once, and when.

type Limits

type Limits struct {
	Days  []string `json:"days"`
	Start string   `json:"start,omitempty"`
	End   string   `json:"end,omitempty"`
}

Limits cut the Shifts of a Rotation layer to some days of the week and, when Start and End are set, a time of day, HH:MM. An End earlier than Start crosses midnight: each window runs from Start on a day it names until End on the next day, so it belongs to the day it starts on.

type ListFilter

type ListFilter struct {
	Team     string
	MemberID int64
	Query    string
	After    *Position
	Limit    int
}

ListFilter selects a page of Schedules by name: of the Team Team, or of the Teams of the User MemberID, when set, matching Query, after the position After.

type Override

type Override struct {
	ID       int64
	PublicID string
	User     Person
	Replaces *Person
	// ReplacesID is the internal id of Replaces, 0 for none, where a read gives it.
	ReplacesID int64
	Start      time.Time
	End        time.Time
	CreatedBy  Actor
	CreatedAt  time.Time
	Version    int64
}

Override puts User On-call from Start to End on top of every Rotation layer; Replaces, the person whose Shift it takes, changes nothing in the On-call (C-27.FR-3).

type OverrideFilter

type OverrideFilter struct {
	From  *time.Time
	To    *time.Time
	After *OverridePosition
	Limit int
}

OverrideFilter selects a page of the Overrides of a Schedule by start: those that end after From, the business clock's now when nil, and start before To when set, after the position After.

type OverrideInput

type OverrideInput struct {
	UserID         string
	ReplacesUserID string
	Start          time.Time
	End            time.Time
}

OverrideInput is what createScheduleOverride and updateScheduleOverride write; an empty ReplacesUserID is none.

type OverridePage

type OverridePage struct {
	Overrides []Override
	Next      *OverridePosition
}

OverridePage is a page of Overrides; Next is nil on the last page.

type OverridePosition

type OverridePosition struct {
	Start time.Time `json:"s"`
	ID    int64     `json:"i"`
}

OverridePosition is the place of an Override in the list: its start and its id.

type Page

type Page struct {
	Schedules []Schedule
	Next      *Position
}

Page is a page of Schedules; Next, the position to continue after, is nil on the last page.

type Person

type Person struct {
	ID       int64
	PublicID string
	Name     string
	Login    string
	Role     string
	Status   string
}

Person is a User as a Schedule names them, with what decides whether they may be Paged.

type Position

type Position struct {
	Name string `json:"n"`
	ID   int64  `json:"i"`
}

Position is the place of a Schedule in the list by name: its lowered name and its id.

type Queries

type Queries interface {
	GetOrganizationTimeZone(ctx context.Context, orgID int64) (string, error)
	LockScheduleTeam(ctx context.Context, arg dbgen.LockScheduleTeamParams) (dbgen.LockScheduleTeamRow, error)
	LockScheduleTeamByID(ctx context.Context, arg dbgen.LockScheduleTeamByIDParams) (dbgen.LockScheduleTeamByIDRow,
		error)
	CountTeamSchedules(ctx context.Context, arg dbgen.CountTeamSchedulesParams) (int64, error)
	ListSchedules(ctx context.Context, arg dbgen.ListSchedulesParams) ([]dbgen.ListSchedulesRow, error)
	GetTeamMainSchedule(ctx context.Context, arg dbgen.GetTeamMainScheduleParams) (dbgen.GetTeamMainScheduleRow,
		error)
	GetSchedule(ctx context.Context, arg dbgen.GetScheduleParams) (dbgen.GetScheduleRow, error)
	FindScheduleTeam(ctx context.Context, arg dbgen.FindScheduleTeamParams) (int64, error)
	LockSchedule(ctx context.Context, arg dbgen.LockScheduleParams) (int64, error)
	InsertSchedule(ctx context.Context, arg dbgen.InsertScheduleParams) (int64, error)
	UpdateSchedule(ctx context.Context, arg dbgen.UpdateScheduleParams) error
	ClearMainSchedule(ctx context.Context, arg dbgen.ClearMainScheduleParams) ([]dbgen.ClearMainScheduleRow, error)
	DeleteSchedule(ctx context.Context, arg dbgen.DeleteScheduleParams) error
	ListRotationLayers(ctx context.Context, arg dbgen.ListRotationLayersParams) ([]dbgen.ListRotationLayersRow, error)
	ListRotationLayerUsers(ctx context.Context, arg dbgen.ListRotationLayerUsersParams) (
		[]dbgen.ListRotationLayerUsersRow, error)
	InsertRotationLayer(ctx context.Context, arg dbgen.InsertRotationLayerParams) (int64, error)
	UpdateRotationLayer(ctx context.Context, arg dbgen.UpdateRotationLayerParams) error
	DeleteRotationLayers(ctx context.Context, arg dbgen.DeleteRotationLayersParams) error
	DeleteRotationLayerUsers(ctx context.Context, arg dbgen.DeleteRotationLayerUsersParams) error
	InsertRotationLayerUsers(ctx context.Context, arg dbgen.InsertRotationLayerUsersParams) error
	LookupUsers(ctx context.Context, arg dbgen.LookupUsersParams) ([]dbgen.LookupUsersRow, error)
	FindUser(ctx context.Context, arg dbgen.FindUserParams) (int64, error)
	ListPageable(ctx context.Context, arg dbgen.ListPageableParams) ([]dbgen.ListPageableRow, error)
	ListScheduleChains(ctx context.Context, arg dbgen.ListScheduleChainsParams) ([]dbgen.ListScheduleChainsRow, error)
	ListPageableInTeams(ctx context.Context, arg dbgen.ListPageableInTeamsParams) ([]dbgen.ListPageableInTeamsRow,
		error)
	IsTeamUser(ctx context.Context, arg dbgen.IsTeamUserParams) (bool, error)
	ListScheduleOverrides(ctx context.Context, arg dbgen.ListScheduleOverridesParams) (
		[]dbgen.ListScheduleOverridesRow, error)
	ListPeriodOverrides(ctx context.Context, arg dbgen.ListPeriodOverridesParams) ([]dbgen.ListPeriodOverridesRow,
		error)
	GetScheduleOverride(ctx context.Context, arg dbgen.GetScheduleOverrideParams) (dbgen.GetScheduleOverrideRow, error)
	CountOverlappingOverrides(ctx context.Context, arg dbgen.CountOverlappingOverridesParams) (int64, error)
	LockScheduleOverride(ctx context.Context, arg dbgen.LockScheduleOverrideParams) (int64, error)
	InsertScheduleOverride(ctx context.Context, arg dbgen.InsertScheduleOverrideParams) (int64, error)
	UpdateScheduleOverride(ctx context.Context, arg dbgen.UpdateScheduleOverrideParams) error
	DeleteScheduleOverride(ctx context.Context, arg dbgen.DeleteScheduleOverrideParams) error
	ListScheduleInfo(ctx context.Context, orgID int64) ([]dbgen.ListScheduleInfoRow, error)
	ListGapScanSchedules(ctx context.Context, orgID int64) ([]dbgen.ListGapScanSchedulesRow, error)
	GetOrganizationTeamLabel(ctx context.Context, orgID int64) (string, error)
	ListOnCallTeams(ctx context.Context, arg dbgen.ListOnCallTeamsParams) ([]dbgen.ListOnCallTeamsRow, error)
	ListTeamReach(ctx context.Context, arg dbgen.ListTeamReachParams) ([]dbgen.ListTeamReachRow, error)
	ListChainReach(ctx context.Context, arg dbgen.ListChainReachParams) ([]dbgen.ListChainReachRow, error)
	ListAccountLinkSpaces(ctx context.Context, arg dbgen.ListAccountLinkSpacesParams) (
		[]dbgen.ListAccountLinkSpacesRow, error)
	ListGatewayReachUsers(ctx context.Context, arg dbgen.ListGatewayReachUsersParams) ([]int64, error)
	audit.Store
	Notify(ctx context.Context, h db.Hint) error
}

Queries are the queries of the package, with the insert of the Audit log and the live hint.

type Referrer

type Referrer struct {
	Type     string
	PublicID string
	Name     string
}

Referrer is an object that holds a Schedule: its kind, public_id and name.

type Requester

type Requester struct {
	Actor     audit.Actor
	Transport audit.Transport
	Address   netip.Addr
	Admin     bool
}

Requester is who asks for a change and how: the actor and the Transport of the Audit log entry, the client address, and whether the caller's Role is Admin, which the precondition of Overrides reads.

type Result

type Result struct {
	From, To       time.Time
	Segments       []Segment
	RotationLayers []RotationLayerShifts
	Overrides      []Override
	Warnings       []Warning
}

Result is the Result of a Schedule over a period: its segments, the Shifts of each Rotation layer, from the lowest, the Overrides in the period, in the order they were created, and the warnings.

func (Result) Gaps

func (r Result) Gaps() []Gap

Gaps are the gaps of the Result in order, cut to its period: its segments without a person. Adjacent segments of nobody are one segment already, so two gaps never touch.

type RotationLayer

type RotationLayer struct {
	ID           int64
	PublicID     string
	Number       int
	Name         string
	Users        []Person
	ShiftLength  string
	ShiftSeconds int
	HandoverTime string
	HandoverDay  string
	// StartDate is a calendar date, as midnight UTC.
	StartDate time.Time
	Limits    *Limits
}

RotationLayer is a Rotation layer: its people take Shifts in turn from StartDate at HandoverTime, the first person first. Number is its position, 1 for the lowest.

func (RotationLayer) Shifts

func (l RotationLayer) Shifts(loc *time.Location, from, to time.Time) []Shift

Shifts are the Shifts of the layer that overlap the period from from to to in the time zone loc, cut to its limits and to the period, in order. A layer without people has none. Every Shift lasts at least an hour, so the loop takes at most one step per hour of the period, and a few more.

type RotationLayerInput

type RotationLayerInput struct {
	ID           string
	Name         string
	UserIDs      []string
	ShiftLength  string
	ShiftSeconds *int
	HandoverTime string
	HandoverDay  string
	// StartDate is a calendar date, as midnight UTC.
	StartDate time.Time
	Limits    *Limits
}

RotationLayerInput is a Rotation layer of an Input; an ID names one of the Schedule's, which keeps its identity.

type RotationLayerRef

type RotationLayerRef struct {
	PublicID string
	Name     string
}

RotationLayerRef names a Rotation layer.

type RotationLayerShift

type RotationLayerShift struct {
	Shift
	Skipped string
}

RotationLayerShift is a Shift of a Rotation layer in the Result, with why it is skipped, empty when it is not.

type RotationLayerShifts

type RotationLayerShifts struct {
	RotationLayer RotationLayerRef
	Shifts        []RotationLayerShift
}

RotationLayerShifts are the Shifts of one Rotation layer in the period.

type Schedule

type Schedule struct {
	ID             int64
	PublicID       string
	Name           string
	TimeZone       string
	Main           bool
	GapAlert       string
	Team           TeamRef
	RotationLayers []RotationLayer
	CreatedAt      time.Time
	Version        int64
	NextGap        *Gap
	// ManagedBy is the tool that keeps the Schedule as code, nil for none (C-33.FR-11).
	ManagedBy *string
}

Schedule is a Schedule as the API reads it, with its Rotation layers from the lowest. NextGap, which the reads of the API set, is the first gap within schedule.gap_view from the business clock's now, nil when there is none.

func (Schedule) GapAlertActive

func (sc Schedule) GapAlertActive() bool

GapAlertActive reports whether the Schedule reports its gaps as MusterScheduleGap: with gap_alert on, and with by_default while it is its Team's main Schedule (C-27.FR-7).

type Segment

type Segment struct {
	Start, End time.Time
	User       *Person
	Source     *Source
}

Segment is a segment of the Result with the person On-call in it, or nobody — a gap — when User is nil.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service holds the Schedules of the Organization.

func New

func New(cfg Config) *Service

New returns the Service of the Organization in cfg.

func (*Service) Create

func (s *Service) Create(ctx context.Context, r Requester, in Input) (Schedule, error)

Create creates a Schedule of a Team (C-27.FR-1). The first Schedule of a Team is its main one (P-90); Main true makes a later one main instead of the previous one.

func (*Service) CreateOverride

func (s *Service) CreateOverride(ctx context.Context, r Requester, scheduleID string, in OverrideInput) (Override,
	error)

CreateOverride creates an Override of the Schedule scheduleID (C-27.FR-3, FR-6): no approval and no message.

func (*Service) Delete

func (s *Service) Delete(ctx context.Context, r Requester, publicID string, version *int64) error

Delete deletes the Schedule publicID with its Rotation layers and Overrides; a non-nil version must be its current one. A Schedule that Referrers names is refused with InUseError (C-27.FR-12); deleting a Team's main Schedule leaves the Team without one (P-66).

func (*Service) DeleteOverride

func (s *Service) DeleteOverride(ctx context.Context, r Requester, scheduleID, overrideID string,
	version *int64) error

DeleteOverride deletes the Override overrideID of the Schedule scheduleID; a non-nil version must be its current one. An Override that has ended is ErrOverrideEnded, so that the past Result stays as it was. One that has begun is ended now instead: its end becomes the business clock's now, and its past part stays in the Result; the Audit log records the deletion with that change of the end.

func (*Service) Get

func (s *Service) Get(ctx context.Context, publicID string) (Schedule, error)

Get reads the Schedule publicID with its Rotation layers and its next gap.

func (*Service) InfoChanged

func (s *Service) InfoChanged()

InfoChanged asks RunInfo to refresh muster_schedule_info: a hint said a Schedule changed, maybe on another replica. It never blocks.

func (*Service) List

func (s *Service) List(ctx context.Context, f ListFilter) (Page, error)

List lists a page of the Schedules by name.

func (*Service) OnCall

func (s *Service) OnCall(ctx context.Context, scheduleID string, from, to *time.Time) (Result, error)

OnCall is the Result of the Schedule scheduleID from from to to: by default from the business clock's now to schedule.gap_view after it, with the warnings of its gaps and of the segments whose On-call a Destination of the Team cannot mention (C-27.FR-7, FR-8). A from or a to more than Reach from now is an out_of_range FieldError at /query/from or /query/to; so is a to that is not after from, or later than the length of ical.window after it.

func (*Service) OnCallAt

func (s *Service) OnCallAt(ctx context.Context, scheduleID string, t time.Time) (Segment, error)

OnCallAt is the person On-call in the Schedule scheduleID at t and what decides it, nil in a gap (C-27.FR-4).

func (*Service) OnCallAtIn

func (s *Service) OnCallAtIn(ctx context.Context, db mentions.DBTX, scheduleID string, t time.Time) (Segment, error)

OnCallAtIn is OnCallAt read through db, the transaction of the caller, such as the step of an Escalation chain that holds its Alert Group's lock, or the main pool for a nil one.

func (*Service) OnCallNow

func (s *Service) OnCallNow(ctx context.Context, memberID int64) ([]TeamOnCall, error)

OnCallNow lists every Team that is not deleted by name — or with memberID those of that User, "My Teams" — each with the On-call of its main Schedule now, until when, what follows and the Destinations of the Schedule's reach that cannot mention them (C-27.FR-8, FR-9). The Results of the main Schedules are computed together, from the business clock's now over schedule.gap_view, and the reach of their On-calls is read once.

func (*Service) Overrides

func (s *Service) Overrides(ctx context.Context, scheduleID string, f OverrideFilter) (OverridePage, error)

Overrides lists a page of the Overrides of the Schedule scheduleID by start.

func (*Service) Referrers

func (s *Service) Referrers(ctx context.Context, q Queries, sc Schedule) ([]Referrer, error)

Referrers lists what names the Schedule, which refuses its deletion: the Escalation chains whose steps name it, each once, by name (C-27.FR-12). It reads escalation_steps with a query of its own, so that the package imports no package of Paging; the deletion holds the Schedule locked, which a save of a chain naming it waits for.

func (*Service) RefreshInfo

func (s *Service) RefreshInfo(ctx context.Context) error

RefreshInfo makes muster_schedule_info list exactly the Schedules the database has, whichever replica changed them (C-27.FR-13).

func (*Service) RunInfo

func (s *Service) RunInfo(ctx context.Context, ticks <-chan time.Time)

RunInfo keeps muster_schedule_info current until ctx ends: it refreshes it at once, after InfoChanged and at every tick, which also repairs a refresh that failed.

func (*Service) TeamOnCallAt

func (s *Service) TeamOnCallAt(ctx context.Context, db mentions.DBTX, teamID int64, t time.Time) (int64, bool,
	error)

TeamOnCallAt is the User on Shift in the main Schedule of the Team teamID at t, by id (C-27.FR-4), and false for a Team that is deleted, without a main Schedule, or in a gap of it at t: the On-call that a Mention entry mentions (C-28.FR-3). It reads through db, the transaction of the resolution, or the main pool for a nil one, so that a caller that holds a connection of the pool takes no second one. It satisfies the interface OnCalls that internal/mentions declares.

func (*Service) Update

func (s *Service) Update(ctx context.Context, r Requester, publicID string, version *int64, in Input) (Schedule,
	error)

Update replaces the configured fields and the Rotation layers of the Schedule publicID; a non-nil version must be its current one (If-Match). The Team stays (settled 4), the main Schedule cannot be unmarked (settled 5), and only the people a save adds to a Rotation layer must be able to be Paged (settled 6). An update that changes nothing writes nothing.

func (*Service) UpdateOverride

func (s *Service) UpdateOverride(ctx context.Context, r Requester, scheduleID, overrideID string, version *int64,
	in OverrideInput) (Override, error)

UpdateOverride replaces the people and the span of the Override overrideID of the Schedule scheduleID; a non-nil version must be its current one. An Override that has ended is ErrOverrideEnded (settled 3); one that has begun only changes its end. A change that changes nothing writes nothing and keeps the version.

type Shift

type Shift struct {
	Start, End time.Time
	User       Person
}

Shift is the time one person of a Rotation layer is on Shift, cut to the limits of the layer.

type Source

type Source struct {
	Kind          string
	Override      string
	RotationLayer RotationLayerRef
}

Source is what decides a segment of the Result: an Override, or a Rotation layer.

type Store

type Store interface {
	Queries
	InTx(ctx context.Context, f func(Queries) error) error
	// On are the queries in a caller's transaction tx.
	On(tx dbgen.DBTX) Queries
	InAlertsTx(ctx context.Context, f func(internalalerts.Store) error) error
}

Store runs the queries alone or in one transaction, and the writes of the gap scan, the Internal alerts of the built-in Integration, in a transaction of their own.

func NewStore

func NewStore(pool *pgxpool.Pool) Store

NewStore is the Store over the main pool.

type TeamOnCall

type TeamOnCall struct {
	Team     TeamRef
	Schedule *Schedule
	Current  *Segment
	Next     *Segment
	// Until is the end of the current segment, nil when it lasts beyond schedule.gap_view.
	Until       *time.Time
	Unreachable []Unreachable
}

TeamOnCall is a Team in "On call now" (C-27.FR-9): its main Schedule, nil for a Team without one, with the segment of its Result at the business clock's now and the one that follows within schedule.gap_view, nil when the current one lasts beyond it. A segment without a person is a gap. Unreachable are the Destinations of the Team, and those in whose Threads the chains that Page the main Schedule write, that a Mention of the current On-call cannot reach (C-27.FR-8), empty in a gap and without a main Schedule.

type TeamRef

type TeamRef struct {
	ID       int64
	PublicID string
	Name     string
	Slug     string
	Deleted  bool
}

TeamRef names the Team of a Schedule.

type Unreachable

type Unreachable struct {
	Destination DestinationRef
	Messenger   string
	Reason      string
	// GatewayReaches is whether the person has a confirmed contact at a Notification gateway, so that a call through
	// it reaches them (C-27.FR-8); whether that gateway is Broken is not considered.
	GatewayReaches bool
}

Unreachable is a Destination that a Mention of a person cannot reach, with the messenger — the Destination's type: its Connection's, or webhook — and why (OnCallReach).

type Warning

type Warning struct {
	Kind          string
	User          Person
	RotationLayer *RotationLayerRef
	Override      string
	Start, End    time.Time
	Unreachable   *Unreachable
}

Warning names a person of a Rotation layer or of an Override in the period who may not be Paged; with the kind gap a gap of the period, from Start to End, and no person; or with the kind unreachable a segment from Start to End in which a Mention of its person, On-call by the Rotation layer or the Override, cannot reach Unreachable.Destination.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL