Documentation
¶
Index ¶
- func CopyStore(from, to *Limit)
- type Limit
- func (l *Limit) ExportAll() ([]byte, error)
- func (l *Limit) FlushAll()
- func (l *Limit) GetActivityFromSessionID(sid string) (*models.Activity, error)
- func (l *Limit) GetAllActivities() map[string]*models.Activity
- func (l *Limit) GetAllActivitiesCount() int
- func (l *Limit) GetAllSessionCount() int
- func (l *Limit) GetLastBookingEnds() int64
- func (l *Limit) GetLockBookings() bool
- func (l *Limit) GetMax() int
- func (l *Limit) GetMessage() string
- func (l *Limit) GetUserActivities(user string) (map[string]*models.Activity, error)
- func (l *Limit) GetUserSessionCount(user string) int
- func (l *Limit) LockBookings()
- func (l *Limit) PostImportEssential(ctx context.Context)
- func (l *Limit) ProvisionalRequest(userID string, exp int64) (func(), func(activity *models.Activity), string, error)
- func (l *Limit) Request(who string, exp int64) (string, error)
- func (l *Limit) Reset()
- func (l *Limit) SetMessage(msg string)
- func (l *Limit) SetNow(now func() int64)
- func (l *Limit) UnlockBookings()
- func (l *Limit) WithFlush(interval time.Duration) *Limit
- func (l *Limit) WithMax(max int) *Limit
- func (l *Limit) WithNow(now func() int64) *Limit
- func (l *Limit) WithProvisionalPeriod(interval time.Duration) *Limit
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Limit ¶
type Limit struct {
*sync.Mutex `json:"-"`
// activities represents users' activities
// it maps each user id to a map of their sessionIDs and activities
Activities map[string]map[string]*models.Activity `json:"activities"`
// sessions represents the expiry time of current sessions
// it maps user id to map of session ids and expiry times
Sessions map[string]map[string]int64 `json:"sessions"`
// activityBySession represents all activities
// use for reverse look up activity by sessionID
ActivityBySession map[string]*models.Activity `json:"activityBySession"`
// userBySession represents all users
// sue for reverse look up user by sessionID
UserBySession map[string]string `json:"userBySession"`
// lastFlush represents the last time a FlushAll() was done
// There is no point in flushing more often than the clock granularity
// of one second
LastFlush *int64 `json:"lastFlush"`
// lastBookingEnds represents the expiry time of the longest running session
// when new bookings are confirmed, this is updated
LastBookingEnds *int64 `json:"lastBookingEnds"`
// max represents the per-user maximum number of concurrent sessions
// there is no limit on historical usage within this package
Max *int `json:"max"`
// lockBookings represents whether there is a lock on bookings
// locking bookings prevents new bookings, letting
// existing bookings continue
Locked *bool `json:"lockBookings"`
// Message represents a status comment that e.g.
// useful for letting users know why the
// lock is applied, or when bookings will be
// locked/unlocked next
Message *string `json:"message"`
// flusInterval represents the time delay between automated FlushAll calls
// these are intended to prevent inadvertent memory leakage
FlushInterval *time.Duration `json:"flushInterval"`
// provisionalPeriod represents the time that a booking can remain unresolved
// into a cancellation or a confirmation with an activity
// failing to either cancel or confirm, results in the user being treated
// as if they confirmed the booking, in terms of quota, but they cannot
// access the activity details again.
ProvisionalPeriod *time.Duration `json:"provisionalPeriod"`
// Now represents a function that returns the current time (mockable for non-timer parts of
// of the package)
Now func() int64 `json:"-"`
// contains filtered or unexported fields
}
Limit represents allocation of limited resources
func ImportAll ¶
ImportAll takes the booking store marshalled into b as our new bookingstore manage pointer scope by making this return the pointer for the calling function to replace the poolstore pointer with
func (*Limit) FlushAll ¶
func (l *Limit) FlushAll()
FlushAll removes all stale entries from all maps
func (*Limit) GetActivityFromSessionID ¶
GetActivityFromSessionID allows an activity to be retrieved even if the userID has been lost -> admin scope only!
func (*Limit) GetAllActivities ¶
GetAllActivities returns a map of all activities by session This must be for admin use only - else anyone can use anyone else's sessions - activities contain credentials
func (*Limit) GetAllActivitiesCount ¶
GetAllActivitiesCount returns a count of how many activities there are
func (*Limit) GetAllSessionCount ¶
GetAllSessionCount is primarily an admin function for a bit of dashboard eye-candy, but there is no reason that users can't see this too
func (*Limit) GetLastBookingEnds ¶
GetLastBookingEnds is an admin function to help figure out how long until the system is free of booked sessions e.g. after disabling new bookings, existing bookings will still have some time to run
func (*Limit) GetLockBookings ¶
GetLockBookings returns bookings are locked (true is locked)
func (*Limit) GetMessage ¶
GetMessage returns the message of the day
func (*Limit) GetUserActivities ¶
GetUserActivities provides pointers to all of a users activities, so that they can be provided with their current bookings (intended for both user and admin scope)
func (*Limit) GetUserSessionCount ¶
GetUserSessionCount returns number of current sessions a user has
func (*Limit) PostImportEssential ¶
PostImportEssential sets up mutexes and Now() functions Assume the original bookingstore context was cancelled so as to stop the registerhandler and flush....
func (*Limit) ProvisionalRequest ¶
func (l *Limit) ProvisionalRequest(userID string, exp int64) (func(), func(activity *models.Activity), string, error)
ProvisionalRequest checks if a user has spare capacity within their limit If so, a provisional booking is made, and cancel and confirm functions are returned along with the sessionID The session should either be cancelled, or confirmed with argument to models.Activity so that booking details can be retrieved again later in the booking if need be, from this store. If there is no quota left, or new bookings are suspended, an error is returned
func (*Limit) Request ¶
Request is primarily for testing purposes but may be useful in some other context so remains exported
func (*Limit) Reset ¶
func (l *Limit) Reset()
Reset the limit store to its original default state (loses all data)
func (*Limit) SetMessage ¶
SetMessage sets the message of the day
func (*Limit) WithFlush ¶
WithFlush adds a periodic flush to avoid memory leakage Use this in production