Documentation ¶
Index ¶
- Constants
- Variables
- func GetDateSpans(event Event, view timespan.Span, exdates ...[]timespan.Span) ([]timespan.Span, error)
- func GetTimeSpans(event Event, view timespan.Span, exdates ...[]timespan.Span) ([]timespan.Span, error)
- func NewPBehaviorInfo(result ResolveResult) types.PbehaviorInfo
- func NewTypeResolver(matcher EntityMatcher, span timespan.Span, ...) *typeResolver
- type Comment
- type Comments
- type ComputeResult
- type ComputeTask
- type ComputedPbehavior
- type Computer
- type EntityMatcher
- type Event
- type EventManager
- type Exception
- type Exdate
- type ModelProvider
- type PBehavior
- type Reason
- type ResolveResult
- type Service
- type Type
- type TypeComputer
- type TypeResolver
Constants ¶
const ( OperationCreate = iota OperationUpdate OperationDelete )
const ( CalculateAll = "" CalculateNone = "none" )
const ( PBehaviorCollectionName = mongo.PbehaviorMongoCollection TypeCollectionName = mongo.PbehaviorTypeMongoCollection )
const ( TypeActive = "active" TypeMaintenance = "maintenance" TypePause = "pause" TypeInactive = "inactive" )
const DefaultPoolSize = 10
const (
ExceptionCollectionName = mongo.PbehaviorExceptionMongoCollection
)
const (
ReasonCollectionName = mongo.PbehaviorReasonMongoCollection
)
Variables ¶
var ErrRecomputeNeed = errors.New("provided time is out of computed date, probably need recompute data")
Functions ¶
func GetDateSpans ¶
func GetDateSpans(event Event, view timespan.Span, exdates ...[]timespan.Span) ([]timespan.Span, error)
GetDateSpans returns all date spans of event within view.
func GetTimeSpans ¶
func GetTimeSpans(event Event, view timespan.Span, exdates ...[]timespan.Span) ([]timespan.Span, error)
GetTimeSpans returns all time spans of event within view.
func NewPBehaviorInfo ¶
func NewPBehaviorInfo(result ResolveResult) types.PbehaviorInfo
func NewTypeResolver ¶
func NewTypeResolver( matcher EntityMatcher, span timespan.Span, computedPbehaviors map[string]ComputedPbehavior, typesByID map[string]*Type, defaultActiveTypeID string, logger zerolog.Logger, workerPoolSize ...int, ) *typeResolver
NewTypeResolver creates new type resolver.
Types ¶
type ComputeResult ¶
type ComputeResult struct {
// contains filtered or unexported fields
}
ComputeResult represents computed data.
type ComputeTask ¶
type ComputedPbehavior ¶
type ComputedPbehavior struct { Name string `json:"n"` Reason string `json:"r"` Filter string `json:"f"` Types []computedType `json:"t"` Created int64 `json:"c"` }
ComputedPbehavior represents all computed types for periodical behavior. Computed types are sorted: - time spans which are defined by exdate - time spans which are defined by rrule - time spans which are defined by default inactive interval of active pbehavior For example, for active daily periodical behavior at 10:00-12:00 and date 2020-06-01: [2020-06-01T10:00, 2020-06-01T12:00] ActiveTypeID [2020-06-01T00:00, 2020-06-02T00:00] InactiveTypeID
type Computer ¶
type Computer interface { // Compute recomputes all pbehaviors on empty signal // or recomputes only one pbehavior on signal which conatins pbehavior id. Compute(ctx context.Context, ch <-chan ComputeTask) }
Computer is used to implement pbehavior intervals recompute on singnal from channel.
func NewCancelableComputer ¶
func NewCancelableComputer( lockClient redis.LockClient, redisStore redis.Store, service Service, dbClient mongo.DbClient, publisher libamqp.Publisher, eventManager EventManager, encoder encoding.Encoder, queue string, logger zerolog.Logger, ) Computer
NewCancelableComputer creates new computer.
type EntityMatcher ¶
type EntityMatcher interface { Match(ctx context.Context, entityID string, filter string) (bool, error) MatchAll(ctx context.Context, entityID string, filters map[string]string) (map[string]bool, error) }
EntityMatcher checks if an entity is matched to filter.
func NewEntityMatcher ¶
func NewEntityMatcher(dbClient mongo.DbClient, aggregationStep ...int) EntityMatcher
NewEntityMatcher creates new matcher.
type Event ¶
type Event struct {
// contains filtered or unexported fields
}
Event represents a recurrent calendar event.
func NewRecEvent ¶
NewRecEvent creates a new recurrent event with the given start and end times and recurrent rule.
type EventManager ¶
func NewEventManager ¶
func NewEventManager() EventManager
type ModelProvider ¶
type ModelProvider interface { // GetTypes returns types by id. GetTypes(ctx context.Context) (map[string]*Type, error) // GetPbehaviors returns pbehaviors by id. GetEnabledPbehaviors(ctx context.Context) (map[string]*PBehavior, error) // GetPbehavior returns pbehavior. GetEnabledPbehavior(ctx context.Context, id string) (*PBehavior, error) // GetExceptions returns exceptions by id. GetExceptions(ctx context.Context) (map[string]*Exception, error) // GetReasons returns reasons by id. GetReasons(ctx context.Context) (map[string]*Reason, error) }
ModelProvider is used to implement fetching models from storage.
func NewModelProvider ¶
func NewModelProvider(dbClient mongo.DbClient) ModelProvider
NewModelProvider creates new model provider.
type PBehavior ¶
type PBehavior struct { ID string `bson:"_id,omitempty"` Author string `bson:"author"` Comments Comments `bson:"comments,omitempty"` Enabled bool `bson:"enabled"` Filter string `bson:"filter"` Name string `bson:"name"` Reason string `bson:"reason"` RRule string `bson:"rrule"` Start *types.CpsTime `bson:"tstart"` Stop *types.CpsTime `bson:"tstop,omitempty"` Type string `bson:"type_"` Exdates []Exdate `bson:"exdates"` Exceptions []string `bson:"exceptions"` Created types.CpsTime `bson:"created,omitempty"` Updated types.CpsTime `bson:"updated,omitempty"` }
PBehavior represents a canopsis periodical behavior.
type ResolveResult ¶
type ResolveResult struct { ResolvedType *Type ResolvedPbhID string ResolvedPbhName string ResolvedPbhReason string ResolvedCreated int64 }
ResolveResult represents current state of entity.
type Service ¶
type Service interface { Resolve(ctx context.Context, entity *libtypes.Entity, t time.Time) (ResolveResult, error) Compute(ctx context.Context, span timespan.Span) error Recompute(ctx context.Context, pbehaviorID string) error GetSpan() timespan.Span GetPbehaviorStatus(ctx context.Context, pbehaviorIDs []string, t time.Time) (map[string]bool, error) }
Service computes pbehavior timespans and figures out state of provided entity by computed data.
func NewService ¶
func NewService( modelProvider ModelProvider, matcher EntityMatcher, logger zerolog.Logger, workerPoolSize ...int, ) Service
NewService creates new service.
type Type ¶
type Type struct { ID string `bson:"_id,omitempty" json:"_id,omitempty"` Name string `bson:"name" json:"name"` Description string `bson:"description" json:"description"` Type string `bson:"type" json:"type"` Priority int `bson:"priority" json:"priority"` IconName string `bson:"icon_name" json:"icon_name"` Color string `bson:"color,omitempty" json:"color,omitempty"` }
type TypeComputer ¶
type TypeComputer interface { // Compute calculates types for provided timespan. Compute(ctx context.Context, span timespan.Span) (*ComputeResult, error) Recompute(ctx context.Context, span timespan.Span, pbehaviorID string) (*ComputedPbehavior, error) }
TypeComputer is used to compute periodical behavior timespans for provided interval.
func NewTypeComputer ¶
func NewTypeComputer( modelProvider ModelProvider, logger zerolog.Logger, workerPoolSize ...int, ) TypeComputer
NewTypeComputer creates new type resolver.
type TypeResolver ¶
type TypeResolver interface { // Resolve returns current type for entity if there is corresponding periodical behavior. // Otherwise it returns default active type. Resolve(context.Context, *libtypes.Entity, time.Time) (ResolveResult, error) GetSpan() timespan.Span }
TypeResolver figures out in which state provided entity at the moment is.