chores

package
v0.0.0-...-678a821 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2019 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const ErrorLog = "error"
View Source
const InfoLog = "info"

Variables

This section is empty.

Functions

func StartAllActiveChores

func StartAllActiveChores(ctx context.Context) (int, error)

StartAllActiveChores should be run at the start of Marvin to get all active chores up and running. Returns the number of started chores.

Types

type Chore

type Chore struct {
	Name     string        `json:"name"`
	Id       string        `json:"id"`
	Active   bool          `json:"active"`
	Template ChoreTemplate `json:"template"`
	Config   ChoreConfig   `json:"choreSettings"`
	Snapshot []byte        `json:"-"`
}

A chore is a workflow for Marvin to execute. It consists of a number of triggers with callbacks that specify what should happen when a trigger fires.

func FromTemplate

func FromTemplate(ct *ChoreTemplate, name string, inputs map[string]string) (*Chore, error)

FromTemplate creates a new Chore based on a template.

func GetChore

func GetChore(id string) (*Chore, error)

GetChore gets a single chore from the database.

func GetChores

func GetChores() ([]*Chore, error)

GetChores gets all chores from the database.

func (*Chore) ClearLogs

func (c *Chore) ClearLogs() error

ClearLogs deletes all logs associated with this chore

func (*Chore) Delete

func (c *Chore) Delete() error

Delete removes a chore from the database.

func (*Chore) GetLogsUpTo

func (c *Chore) GetLogsUpTo(t time.Time, n int) ([]ChoreLog, error)

GetLogsUpTo returns the n latest logs befofe a specific time t.

func (*Chore) Log

func (c *Chore) Log(logType, message string, args ...interface{}) error

func (*Chore) Save

func (c *Chore) Save() error

Save saves a chore to the database.

func (*Chore) Start

func (c *Chore) Start(ctx context.Context)

Start activates the chore, and starts all triggers.

func (*Chore) Stop

func (c *Chore) Stop()

Stop stops a currently running chore, marking it as inactive.

type ChoreConfig

type ChoreConfig struct {
	// configurable parameters that are used by the script specify behavior.
	Inputs map[string]string `json:"inputs"`

	// The registered triggers, associated with their parameters.
	Triggers []choreTrigger `json:"triggers"`
}

holds configuration data for the chore.

type ChoreLog

type ChoreLog struct {
	Id      string    `json:"id"`
	Time    time.Time `json:"-"`
	TimeStr string    `json:"time"`
	Type    string    `json:"type"`
	Message string    `json:"message"`
}

type ChoreTemplate

type ChoreTemplate struct {
	Name    string              `json:"name"`
	Id      string              `json:"id"`
	Created time.Time           `json:"created"`
	Script  string              `json:"script"`
	Config  ChoreTemplateConfig `json:"templateSettings"`
}

ChoreTemplate is a template for a chore (how surprising!)

func GetChoreTemplates

func GetChoreTemplates() ([]*ChoreTemplate, error)

GetChoreTemplates gets all chore templates from the database.

func LoadChoreTemplate

func LoadChoreTemplate(id string) (*ChoreTemplate, error)

LoadChoreTemplate loads a single template from the database

func NewChoreTemplate

func NewChoreTemplate(name, script string) (*ChoreTemplate, error)

NewChoreTemplate creates a new chore template with the given name and string. It executes the script to determine which triggers are registered, and which inputs are requested.

func (*ChoreTemplate) Delete

func (ct *ChoreTemplate) Delete() error

Delete removes a chore template from the database.

func (*ChoreTemplate) GenerateChoreConfig

func (ct *ChoreTemplate) GenerateChoreConfig(inputValues map[string]string) (*ChoreConfig, error)

GenerateChoreConfig runs the template's script with the given inputs to generate a chore config.

func (*ChoreTemplate) GenerateTemplateConfigs

func (ct *ChoreTemplate) GenerateTemplateConfigs() error

GenerateTemplateConfig runs the script to generate a ChoreTemplateConfig

func (*ChoreTemplate) GetChoreSnapshot

func (ct *ChoreTemplate) GetChoreSnapshot(inputs map[string]string) []byte

GetChoreSnapshot generates a v8 Snapshot with all triggers in the template registered.

func (*ChoreTemplate) Save

func (ct *ChoreTemplate) Save() error

Save stores a chore template to the database.

type ChoreTemplateConfig

type ChoreTemplateConfig struct {
	Triggers []RegisteredTrigger `json:"triggers"`
	Inputs   []ConfigInput       `json:"inputs"`
}

ChoreTemplateConfig holds configuration information about a trigger.

type ConfigInput

type ConfigInput struct {
	Name        string `json:"name"`
	Description string `json:"description"`
}

ConfigInput describes a parameter that is configurable by the user when creating a chore from a template.

type RegisteredTrigger

type RegisteredTrigger struct {
	Provider string `json:"provider"`
	Group    string `json:"group"`
	Action   string `json:"action"`
}

RegisteredTrigger holds information about a trigger, registered in a template.

Jump to

Keyboard shortcuts

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