rule

package
v0.27.0 Latest Latest
Warning

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

Go to latest
Published: May 3, 2021 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

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

func NewDB

func NewDB(ctx context.Context, db *sql.DB) (*DB, error)

func (*DB) Add

func (db *DB) Add(ctx context.Context, r *Rule) (*Rule, error)

func (*DB) CreateRuleTx

func (db *DB) CreateRuleTx(ctx context.Context, tx *sql.Tx, r *Rule) (*Rule, error)

func (*DB) Delete

func (db *DB) Delete(ctx context.Context, ruleID string) error

func (*DB) DeleteByTarget

func (db *DB) DeleteByTarget(ctx context.Context, scheduleID string, target assignment.Target) error

DeleteByTarget removes all rules for a schedule pointing to the specified target.

func (*DB) DeleteManyTx

func (db *DB) DeleteManyTx(ctx context.Context, tx *sql.Tx, ruleIDs []string) error

func (*DB) DeleteTx

func (db *DB) DeleteTx(ctx context.Context, tx *sql.Tx, ruleID string) error

func (*DB) FindAll

func (db *DB) FindAll(ctx context.Context, scheduleID string) ([]Rule, error)

func (*DB) FindAllTx

func (db *DB) FindAllTx(ctx context.Context, tx *sql.Tx, scheduleID string) ([]Rule, error)

func (*DB) FindAllWithUsers

func (db *DB) FindAllWithUsers(ctx context.Context, scheduleID string) ([]Rule, error)

func (*DB) FindByTargetTx

func (db *DB) FindByTargetTx(ctx context.Context, tx *sql.Tx, scheduleID string, target assignment.Target) ([]Rule, error)

func (*DB) FindOne

func (db *DB) FindOne(ctx context.Context, ruleID string) (*Rule, error)

func (*DB) FindScheduleID

func (db *DB) FindScheduleID(ctx context.Context, ruleID string) (string, error)

func (*DB) Update

func (db *DB) Update(ctx context.Context, r *Rule) error

func (*DB) UpdateTx

func (db *DB) UpdateTx(ctx context.Context, tx *sql.Tx, r *Rule) error

type ReadStore

type ReadStore interface {
	FindScheduleID(context.Context, string) (string, error)
	FindOne(context.Context, string) (*Rule, error)
	FindAll(ctx context.Context, scheduleID string) ([]Rule, error)
	FindAllTx(ctx context.Context, tx *sql.Tx, scheduleID string) ([]Rule, error)

	// FindAllWithUsers works like FindAll but resolves rotations to the active user.
	// This is reflected in the Target attribute.
	// Rules pointing to inactive rotations (no participants) are omitted.
	FindAllWithUsers(ctx context.Context, scheduleID string) ([]Rule, error)
}

type Rule

type Rule struct {
	ID         string `json:"id"`
	ScheduleID string `json:"schedule_id"`
	WeekdayFilter
	Start     timeutil.Clock `json:"start"`
	End       timeutil.Clock `json:"end"`
	CreatedAt time.Time      `json:"created_at"`
	Target    assignment.Target
}

func NewAlwaysActive

func NewAlwaysActive(scheduleID string, tgt assignment.Target) *Rule

func (Rule) AlwaysActive

func (r Rule) AlwaysActive() bool

AlwaysActive will return true if the rule will always be active.

func (Rule) EndTime

func (r Rule) EndTime(t time.Time) time.Time

EndTime will return the next time the rule would be inactive. If the rule is currently inactive, it will return the end of the next shift.

If the rule is always active, or never active, it returns a zero time.

func (Rule) IsActive

func (r Rule) IsActive(t time.Time) bool

IsActive determines if the rule is active in the given moment in time, in the location of t.

func (Rule) NeverActive

func (r Rule) NeverActive() bool

NeverActive returns true if the rule will never be active.

func (Rule) Normalize

func (r Rule) Normalize() (*Rule, error)

func (Rule) StartTime

func (r Rule) StartTime(t time.Time) time.Time

StartTime will return the next time the rule would be active. If the rule is currently active, it will return the time it became active (in the past).

If the rule is NeverActive or AlwaysActive, zero time is returned.

It may break when processing a timezone where daylight savings repeats or skips ahead at midnight.

func (Rule) String

func (r Rule) String() string

String returns a human-readable string describing the rule

type ScheduleTriggerFunc

type ScheduleTriggerFunc func(string)

type Store

type Store interface {
	ReadStore
	Add(context.Context, *Rule) (*Rule, error)
	CreateRuleTx(context.Context, *sql.Tx, *Rule) (*Rule, error)
	Update(context.Context, *Rule) error
	UpdateTx(context.Context, *sql.Tx, *Rule) error
	Delete(context.Context, string) error
	DeleteTx(context.Context, *sql.Tx, string) error
	DeleteManyTx(context.Context, *sql.Tx, []string) error
	DeleteByTarget(ctx context.Context, scheduleID string, target assignment.Target) error
	FindByTargetTx(ctx context.Context, tx *sql.Tx, scheduleID string, target assignment.Target) ([]Rule, error)
}

type WeekdayFilter

type WeekdayFilter [7]byte

func EveryDay added in v0.27.0

func EveryDay() WeekdayFilter

EveryDay returns a WeekdayFilter that is permanently active.

func (WeekdayFilter) Day

func (f WeekdayFilter) Day(d time.Weekday) bool

Day will return true if the given weekday is enabled.

func (WeekdayFilter) DaysSince

func (f WeekdayFilter) DaysSince(d time.Weekday, enabled bool) int

DaysSince will give the number of days since an enabled day from the given weekday. -1 is returned if all days are disabled.

func (WeekdayFilter) DaysUntil

func (f WeekdayFilter) DaysUntil(d time.Weekday, enabled bool) int

DaysUntil will give the number of days until a matching day from the given weekday. -1 is returned if no days match.

func (WeekdayFilter) NextActive added in v0.27.0

func (f WeekdayFilter) NextActive(t time.Time) time.Time

NextActive returns the next time, at midnight, from t that is active.

If the filter is active every day or no days, zero time is returned. Otherwise the returned value will always be in the future.

func (WeekdayFilter) NextInactive added in v0.27.0

func (f WeekdayFilter) NextInactive(t time.Time) time.Time

NextInactive returns the next time, at midnight, from t that is no longer active.

If the filter is active every day or no days, zero time is returned. Otherwise the returned value will always be in the future.

func (*WeekdayFilter) Scan added in v0.24.0

func (f *WeekdayFilter) Scan(src interface{}) error

Scan scans the WeekdayFilter from a DB array of bool.

func (*WeekdayFilter) SetDay

func (f *WeekdayFilter) SetDay(d time.Weekday, enabled bool)

SetDay will update the filter for the given weekday.

func (WeekdayFilter) StartTime added in v0.27.0

func (f WeekdayFilter) StartTime(t time.Time) time.Time

StartTime returns midnight of the day the filter became active, from the perspective of t.

If the filter is active every day or no days, zero time is returned. If the current day is not active, zero time is returned.

func (WeekdayFilter) String

func (f WeekdayFilter) String() string

String returns a string representation of the WeekdayFilter.

func (WeekdayFilter) Value

func (f WeekdayFilter) Value() (driver.Value, error)

Value converts the WeekdayFilter to a DB array of bool.

Jump to

Keyboard shortcuts

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