sl

package
v0.0.0-...-b215688 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ReasonTask     = "task"
	ReasonGrace    = "grace"
	ReasonPersonal = "personal"
)
View Source
const (
	AnyLevel = Level(iota)
	BeginnerLevel
	IntermediateLevel
	AdvancedLevel
	ExpertLevel
)
View Source
const (
	AdvancedLevelName       = "advanced"
	AdvancedLevelSymbol     = "◈"
	AnyLevelName            = "any"
	AnyLevelSymbol          = "*"
	BeginnerLevelName       = "beginner"
	BeginnerLevelSymbol     = "◉"
	ExpertLevelName         = "expert"
	ExpertLevelSymbol       = "◈◈"
	IntermediateLevelName   = "intermediate"
	IntermediateLevelSymbol = "▣"
)
View Source
const (
	TaskTypeTicket = types.ID("ticket")
	TaskTypeShift  = types.ID("shift")
)
View Source
const (
	KeyRotation        = "rotation_"
	KeyRotationTasks   = "rotation_tasks_"
	KeyTask            = "task_"
	KeyUser            = "user_"
	KeyKnownSkills     = "known_skills"
	KeyActiveRotations = "active_rotations"
)
View Source
const (
	// New tasks that have been submitted are Pending. There are no restrictions
	// on assigning, filling, or un-assigning users to pending tasks.
	// No DMs are sent to users added to or removed from these tasks.
	TaskStatePending = types.ID("pending")

	// Scheduled tasks are normally verified to have met the requirements and
	// constraints. Assigned users receive a message when a task is scheduled. A
	// scheduled task may no longer be filled, but users can still be assigned
	// and unassigned manually, with DM notifications. Users added to a
	// scheduled task get task-related unavailability events added to their
	// calendars.
	TaskStateScheduled = types.ID("scheduled")

	// An in-progress task. Users can be assigned, but not filled (nor unassigned?).
	TaskStateStarted = types.ID("started")

	// Finished tasks are archived, and are not yet used.
	TaskStateFinished = types.ID("finished")
)

Variables

View Source
var AnySkill = types.ID("any")
View Source
var AnySkillLevel = NewSkillLevel(AnySkill, AnyLevel)
View Source
var ErrAlreadyExists = errors.New("already exists")
View Source
var ErrFillInsufficient = errors.New("insufficient")
View Source
var ErrFillLimit = errors.New("limit violated")
View Source
var ErrMultipleResults = errors.New("multiple results found")
View Source
var ErrWrongState = errors.New("operation is not allowed in this state")
View Source
var NeedOneAnyLevel = NewNeed(1, AnySkillLevel)

Functions

This section is empty.

Types

type AutopilotService

type AutopilotService interface {
	RunAutopilot(in *InRunAutopilot) (*OutRunAutopilot, error)
}

type AutopilotSettings

type AutopilotSettings struct {
	Create            bool          `json:",omitempty"`
	CreatePrior       time.Duration `json:",omitempty"`
	Schedule          bool          `json:",omitempty"`
	SchedulePrior     time.Duration `json:",omitempty"`
	StartFinish       bool          `json:",omitempty"`
	RemindStart       bool          `json:",omitempty"`
	RemindStartPrior  time.Duration `json:",omitempty"`
	RemindFinish      bool          `json:",omitempty"`
	RemindFinishPrior time.Duration `json:",omitempty"`
}

type FillError

type FillError struct {
	Err        error
	FailedNeed *Need
	UnmetNeeds *Needs
	TaskID     types.ID
}

func (FillError) Error

func (e FillError) Error() string

type FillSettings

type FillSettings struct {
	// Beginning marks the time when scheduling starts
	Beginning types.Time

	// Period specifies the recurrence of shifts, but is also used to calculate
	// the user weights when filling tasks.
	Period types.Period

	// Seed is a stable seed to use for rand.
	Seed int64 `json:",omitempty"`

	// Fuzz is the number of periods that gets added to the default doubling
	// duration when calculating user weights.
	Fuzz int64 `json:",omitempty"`
}

type InAddToCalendar

type InAddToCalendar struct {
	MattermostUserIDs *types.IDSet
	Unavailable       *Unavailable
}

type InAssignTask

type InAssignTask struct {
	TaskID            types.ID
	MattermostUserIDs *types.IDSet
	Force             bool
	Time              types.Time
}

type InClearCalendar

type InClearCalendar struct {
	MattermostUserIDs *types.IDSet
	Interval          types.Interval
}

type InCreateShift

type InCreateShift struct {
	RotationID types.ID
	Number     int
	Time       types.Time
}

type InCreateTicket

type InCreateTicket struct {
	RotationID  types.ID
	Summary     string
	Description string
	Time        types.Time
}

type InDisqualify

type InDisqualify struct {
	MattermostUserIDs *types.IDSet
	Skills            []string
}

type InJoinRotation

type InJoinRotation struct {
	MattermostUserIDs *types.IDSet
	RotationID        types.ID
	Starting          types.Time
}

type InQualify

type InQualify struct {
	MattermostUserIDs *types.IDSet
	SkillLevels       []SkillLevel
}

type InRunAutopilot

type InRunAutopilot struct {
	RotationID types.ID
	Time       types.Time
}

type InTransitionTask

type InTransitionTask struct {
	TaskID types.ID
	State  types.ID
	Time   types.Time
}

type Level

type Level int64

func (*Level) Set

func (level *Level) Set(in string) error

func (Level) String

func (level Level) String() string

func (*Level) Type

func (level *Level) Type() string

type Need

type Need struct {
	types.IntValue
}

func NewNeed

func NewNeed(count int64, skillLevel SkillLevel) Need

func (Need) Count

func (need Need) Count() int64

func (Need) Markdown

func (need Need) Markdown() md.MD

func (Need) QualifyUser

func (need Need) QualifyUser(user *User) (bool, Need)

func (Need) QualifyUsers

func (need Need) QualifyUsers(users *Users) (*Users, Need)

func (Need) SkillLevel

func (need Need) SkillLevel() SkillLevel

func (Need) String

func (need Need) String() string

type Needs

type Needs struct {
	types.IntSet
}

Needs is a map of SkillLevel to an int64 headcount needed.

func NewNeeds

func NewNeeds(nn ...Need) *Needs

func (Needs) AsArray

func (needs Needs) AsArray() []Need

func (*Needs) CheckLimits

func (needs *Needs) CheckLimits(user *User) (adjusted, modified, violated *Needs)

func (*Needs) CheckRequired

func (require *Needs) CheckRequired(user *User) (adjusted *Needs)

func (Needs) Clone

func (needs Needs) Clone() *Needs

func (Needs) Get

func (needs Needs) Get(id types.ID) Need

func (Needs) GetCountForSkillLevel

func (needs Needs) GetCountForSkillLevel(skillLevel SkillLevel) int64

func (*Needs) IsEmpty

func (needs *Needs) IsEmpty() bool

func (Needs) Markdown

func (needs Needs) Markdown() md.MD

func (Needs) MarkdownSkillLevels

func (needs Needs) MarkdownSkillLevels() string

func (*Needs) Set

func (needs *Needs) Set(need Need)

func (*Needs) SetCountForSkillLevel

func (needs *Needs) SetCountForSkillLevel(skillLevel SkillLevel, count int64)

func (Needs) String

func (needs Needs) String() string

func (Needs) Unmet

func (needs Needs) Unmet(users *Users) *Needs

type OutAssignTask

type OutAssignTask struct {
	md.MD
	Task    *Task
	Changed *Users
}

type OutCalendar

type OutCalendar struct {
	Users *Users
	md.MD
}

type OutCreateTask

type OutCreateTask struct {
	md.MD
	Task *Task
}

type OutJoinRotation

type OutJoinRotation struct {
	md.MD
	Modified *Users
}

type OutQualify

type OutQualify struct {
	md.MD
	Users *Users
}

type OutRunAutopilot

type OutRunAutopilot struct {
	md.MD
	Rotation *Rotation
	// contains filtered or unexported fields
}

type OutTransitionTask

type OutTransitionTask struct {
	md.MD
	Task      *Task
	PrevState types.ID
}

type PluginAPI

type PluginAPI interface {
	GetMattermostUser(mattermostUserID string) (*model.User, error)
	GetMattermostUserByUsername(mattermostUsername string) (*model.User, error)
	IsPluginAdmin(mattermostUserID string) (bool, error)
	Clean() error
	GetBotUserID() string
}

type Rotation

type Rotation struct {
	PluginVersion string
	RotationID    types.ID
	IsArchived    bool

	FillerType types.ID
	TaskType   types.ID

	MattermostUserIDs *types.IDSet `json:",omitempty"`
	TaskIDs           *types.IDSet `json:",omitempty"`

	TaskSettings      TaskSettings      `json:",omitempty"`
	FillSettings      FillSettings      `json:",omitempty"`
	AutopilotSettings AutopilotSettings `json:",omitempty"`

	Users *Users `json:"-"`
	Tasks *Tasks `json:"-"`
	// contains filtered or unexported fields
}

func NewRotation

func NewRotation() *Rotation

func (*Rotation) FindUsers

func (r *Rotation) FindUsers(mattermostUserIDs *types.IDSet) []*User

func (*Rotation) Init

func (r *Rotation) Init()

func (*Rotation) Markdown

func (r *Rotation) Markdown() md.MD

func (*Rotation) MarkdownBullets

func (r *Rotation) MarkdownBullets() md.MD

func (*Rotation) Name

func (r *Rotation) Name() string

func (*Rotation) String

func (r *Rotation) String() string

func (*Rotation) WithMattermostUserIDs

func (rotation *Rotation) WithMattermostUserIDs(pool *Users) *Rotation

type RotationService

type RotationService interface {
	AddRotation(*Rotation) error
	ArchiveRotation(rotationID types.ID) (*Rotation, error)
	DebugDeleteRotation(rotationID types.ID) error
	LoadActiveRotations() (*types.IDSet, error)
	LoadRotation(rotationID types.ID) (*Rotation, error)
	MakeRotation(rotationName string) (*Rotation, error)
	ResolveRotationName(string) (types.ID, error)
	UpdateRotation(rotationID types.ID, updatef func(*Rotation) error) (*Rotation, error)
}

type SL

type SL interface {
	RotationService
	SkillService
	UserService
	TaskService
	AutopilotService

	PluginAPI
	bot.Logger

	ActingUser() (*User, error)
	Config() *config.Config

	LoadUsers(mattermostUserIDs *types.IDSet) (*Users, error)
	LoadMattermostUserByUsername(username string) (*User, error)
}

type Service

type Service struct {
	PluginAPI
	Config config.Service

	TaskFillers map[types.ID]TaskFiller
	Logger      bot.Logger
	Poster      bot.Poster
	Store       kvstore.Store
}

func (*Service) ActingAs

func (s *Service) ActingAs(mattermostUserID types.ID) SL

func (*Service) Clean

func (s *Service) Clean() error

type SkillLevel

type SkillLevel struct {
	Skill types.ID
	Level Level
}

func NewSkillLevel

func NewSkillLevel(s types.ID, l Level) SkillLevel

func ParseSkillLevel

func ParseSkillLevel(in types.ID) SkillLevel

func (SkillLevel) AsID

func (skillLevel SkillLevel) AsID() types.ID

func (SkillLevel) GetID

func (skillLevel SkillLevel) GetID() types.ID

func (*SkillLevel) Set

func (skillLevel *SkillLevel) Set(in string) error

func (SkillLevel) String

func (skillLevel SkillLevel) String() string

func (SkillLevel) Type

func (skillLevel SkillLevel) Type() string

type SkillService

type SkillService interface {
	ListKnownSkills() (*types.IDSet, error)
	AddKnownSkill(types.ID) error
	DeleteKnownSkill(types.ID) error
}

type Task

type Task struct {
	// TODO set PluginID on save
	PluginVersion string
	TaskID        types.ID
	RotationID    types.ID
	State         types.ID

	ActualFinish            types.Time    `json:",omitempty"`
	ActualStart             types.Time    `json:",omitempty"`
	AutopilotRemindedFinish bool          `json:",omitempty"`
	AutopilotRemindedStart  bool          `json:",omitempty"`
	Description             string        `json:",omitempty"`
	ExpectedDuration        time.Duration `json:",omitempty"`
	ExpectedStart           types.Time    `json:",omitempty"`
	Grace                   time.Duration `json:",omitempty"`
	Limit                   *Needs        `json:",omitempty"`
	MattermostUserIDs       *types.IDSet  `json:",omitempty"`
	Require                 *Needs        `json:",omitempty"`
	Summary                 string        `json:",omitempty"`

	Users *Users `json:"-"`
}

func NewTask

func NewTask(rotationID types.ID) *Task

func (Task) GetID

func (t Task) GetID() types.ID

func (*Task) Interval

func (t *Task) Interval() types.Interval

func (Task) Markdown

func (t Task) Markdown() md.MD

func (Task) MarkdownBullets

func (t Task) MarkdownBullets(rotation *Rotation) md.MD

func (*Task) NewUnavailable

func (t *Task) NewUnavailable() []*Unavailable

func (Task) String

func (t Task) String() string

func (*Task) WrapError

func (t *Task) WrapError(err *error, verb string)

type TaskFiller

type TaskFiller interface {
	FillTask(rotation *Rotation, task *Task, forTime types.Time, logger bot.Logger) (*Users, error)
}

type TaskService

type TaskService interface {
	AssignTask(InAssignTask) (*OutAssignTask, error)
	UnassignTask(InAssignTask) (*OutAssignTask, error)
	FillTask(InAssignTask) (*OutAssignTask, error)
	LoadTask(types.ID) (*Task, error)
	TransitionTask(params InTransitionTask) (*OutTransitionTask, error)
	CreateTicket(InCreateTicket) (*OutCreateTask, error)
	CreateShift(InCreateShift) (*OutCreateTask, error)
}

type TaskSettings

type TaskSettings struct {
	Seq         int           `json:",omitempty"`
	Require     *Needs        `json:",omitempty"`
	Limit       *Needs        `json:",omitempty"`
	Duration    time.Duration `json:",omitempty"`
	Grace       time.Duration `json:",omitempty"`
	Description string        `json:",omitempty"`
}

type Tasks

type Tasks struct {
	*types.ValueSet // of *Task
}

func NewTasks

func NewTasks(tt ...*Task) *Tasks

func (Tasks) AsArray

func (tasks Tasks) AsArray() []*Task

func (Tasks) Get

func (tasks Tasks) Get(id types.ID) *Task

func (Tasks) Markdown

func (tasks Tasks) Markdown() md.MD

func (Tasks) String

func (tasks Tasks) String() string

func (Tasks) TestArray

func (tasks Tasks) TestArray() []Task

TestArray returns all tasks, sorted by MattermostUserID. It is used in testing, so it returns []Task rather than a []*Task to make it easier to compare with expected results.

type Unavailable

type Unavailable struct {
	types.Interval
	Reason string

	TaskID     types.ID
	RotationID types.ID
}

func NewUnavailable

func NewUnavailable(reason string, interval types.Interval) *Unavailable

type User

type User struct {
	PluginVersion    string `json:",omitempty"`
	MattermostUserID types.ID
	SkillLevels      *types.IntSet  `json:",omitempty"` // skill (id) -> level
	LastServed       *types.IntSet  `json:",omitempty"` // Last time completed a task, rotationID -> Unix time.
	Calendar         []*Unavailable `json:",omitempty"` // Sorted by start date of the events.
	// contains filtered or unexported fields
}

func NewUser

func NewUser(mattermostUserID types.ID) *User

func (*User) AddUnavailable

func (user *User) AddUnavailable(uu ...*Unavailable) []*Unavailable

func (*User) ClearUnavailable

func (user *User) ClearUnavailable(matchInterval types.Interval, matchRotationID, matchTaskID types.ID) []*Unavailable

func (*User) FindUnavailable

func (user *User) FindUnavailable(matchInterval types.Interval, matchRotationID, matchTaskID types.ID) []*Unavailable

func (*User) GetID

func (user *User) GetID() types.ID

func (*User) Markdown

func (user *User) Markdown() md.MD

func (*User) MarkdownInterval

func (user *User) MarkdownInterval(i types.Interval) md.MD

func (*User) MarkdownSkills

func (user *User) MarkdownSkills() md.MD

func (*User) MarkdownUnavailable

func (user *User) MarkdownUnavailable(u *Unavailable) md.MD

func (*User) MarkdownWithSkills

func (user *User) MarkdownWithSkills() md.MD

func (User) MattermostUsername

func (user User) MattermostUsername() string

func (*User) ScanUnavailable

func (user *User) ScanUnavailable(matchInterval types.Interval, matchRotationID, matchTaskID types.ID,
	matchf, nonmatchf func(*Unavailable))

func (*User) String

func (user *User) String() string

func (*User) Time

func (user *User) Time(t types.Time) types.Time

func (*User) WithLastServed

func (user *User) WithLastServed(rotationID types.ID, finishTime types.Time) *User

func (*User) WithSkills

func (user *User) WithSkills(skillLevels *types.IntSet) *User

type UserService

type UserService interface {
	AddToCalendar(InAddToCalendar) (*OutCalendar, error)
	ClearCalendar(InClearCalendar) (*OutCalendar, error)
	Disqualify(InDisqualify) (*OutQualify, error)
	JoinRotation(InJoinRotation) (*OutJoinRotation, error)
	LeaveRotation(InJoinRotation) (*OutJoinRotation, error)
	Qualify(InQualify) (*OutQualify, error)
}

type Users

type Users struct {
	types.ValueSet // of *User
}

func NewUsers

func NewUsers(uu ...*User) *Users

func (Users) AsArray

func (users Users) AsArray() []*User

func (Users) Clone

func (users Users) Clone() *Users

func (Users) Get

func (users Users) Get(id types.ID) *User

func (*Users) IsEmpty

func (users *Users) IsEmpty() bool

func (Users) Join

func (users Users) Join(other *Users) *Users

func (Users) Markdown

func (users Users) Markdown() md.MD

func (Users) MarkdownWithSkills

func (users Users) MarkdownWithSkills() string

func (Users) String

func (users Users) String() string

func (Users) TestArray

func (users Users) TestArray() []User

TestArray returns all users, sorted by MattermostUserID. It is used in testing, so it returns []User rather than a []*User to make it easier to compare with expected results.

Directories

Path Synopsis
filler
Package mock_sl is a generated GoMock package.
Package mock_sl is a generated GoMock package.

Jump to

Keyboard shortcuts

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