engine

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: May 30, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package engine implements the NanoCMD workflow engine.

Index

Constants

View Source
const DefaultDuration = time.Minute * 5
View Source
const DefaultRePushDuration = time.Hour * 24
View Source
const DefaultTimeout = time.Hour * 24 * 3

DefaultTimeout is the default workflow step timeout. A workflow's configured timeout will override this default and a step's enqueued timeout will override that.

Variables

View Source
var (
	ErrNoSuchWorkflow = errors.New("no such workflow")
	ErrNoIDs          = errors.New("no IDs")
)

Functions

func NewErrNoSuchWorkflow

func NewErrNoSuchWorkflow(name string) error

Types

type Engine

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

Engine coordinates workflows with MDM servers.

func New

func New(storage storage.Storage, enqueuer Enqueuer, opts ...Option) *Engine

New creates a new NanoCMD engine with default configurations.

func (*Engine) EnqueueStep

func (e *Engine) EnqueueStep(ctx context.Context, n workflow.Namer, se *workflow.StepEnqueueing) error

EnqueueStep stores the step and enqueues the commands to the MDM server.

func (*Engine) MDMCheckinEvent

func (e *Engine) MDMCheckinEvent(ctx context.Context, id string, checkin interface{}, mdmContext *workflow.MDMContext) error

MDMCheckinEvent receives MDM checkin messages.

func (*Engine) MDMCommandResponseEvent

func (e *Engine) MDMCommandResponseEvent(ctx context.Context, id string, uuid string, raw []byte, mdmContext *workflow.MDMContext) error

MDMCommandResponseEvent receives MDM command responses.

func (*Engine) MDMIdleEvent added in v0.3.0

func (e *Engine) MDMIdleEvent(ctx context.Context, id string, raw []byte, mdmContext *workflow.MDMContext, eventAt time.Time) error

MDMIdleEvent is called when an MDM Report Results has an "Idle" status. MDMIdleEvent will dispatch workflow "Idle" events (for workflows that are configured for it) and will also start workflows for the "IdleNotStartedSince" event subscription type. Note: any other event subscription type starting workflows is not supported.

func (*Engine) RegisterWorkflow

func (e *Engine) RegisterWorkflow(w workflow.Workflow) error

RegisterWorkflow associates w with the engine by name.

func (*Engine) StartWorkflow

func (e *Engine) StartWorkflow(ctx context.Context, name string, context []byte, ids []string, ev *workflow.Event, mdmCtx *workflow.MDMContext) (string, error)

StartWorkflow starts a new workflow instance for workflow name.

func (*Engine) UnregisterWorkflow

func (e *Engine) UnregisterWorkflow(name string) error

UnregisterWorkflow dissociates the named workflow from the engine by name.

func (*Engine) Workflow

func (e *Engine) Workflow(name string) workflow.Workflow

Workflow returns the registered workflow by name.

func (*Engine) WorkflowRegistered

func (e *Engine) WorkflowRegistered(name string) bool

WorkflowRegistered returns true if the workflow name is registered.

type Enqueuer

type Enqueuer interface {
	RawEnqueuer
	SupportsMultiCommands() bool
}

Enqueuer sends raw Plist commands to enrollment IDs and relays multi-command capability.

type Option

type Option func(*Engine)

Options configure the engine.

func WithDefaultTimeout

func WithDefaultTimeout(timeout time.Duration) Option

WithDefaultTimeout configures the engine for a default workflow step timeout.

func WithEventStorage

func WithEventStorage(evStorage storage.ReadEventSubscriptionStorage) Option

WithEventStorage turns on the event dispatch and configures the storage.

func WithLogger

func WithLogger(logger log.Logger) Option

WithLogger sets the engine logger.

type PushEnqueuer

type PushEnqueuer interface {
	RawEnqueuer
	Push(ctx context.Context, ids []string) error
}

PushEnqueuer sends raw commands and APNs pushes to enrollment IDs.

type RawEnqueuer

type RawEnqueuer interface {
	Enqueue(ctx context.Context, ids []string, rawCmd []byte) error
}

RawEnqueuer sends raw Plist commands to enrollment IDs.

type Worker

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

Worker polls storage backends for timed events on an interval. Examples include step timeouts, delayed steps (NotUntil), and re-pushes.

func NewWorker

func NewWorker(wff WorkflowFinder, storage storage.WorkerStorage, enqueuer PushEnqueuer, opts ...WorkerOption) *Worker

func (*Worker) Run

func (w *Worker) Run(ctx context.Context) error

Run starts and runs the worker forever on an interval.

func (*Worker) RunOnce

func (w *Worker) RunOnce(ctx context.Context) error

RunOnce runs the processes of the worker and logs errors.

type WorkerOption

type WorkerOption func(w *Worker)

func WithWorkerDuration

func WithWorkerDuration(d time.Duration) WorkerOption

WithWorkerDuration configures the polling interval for the worker.

func WithWorkerLogger

func WithWorkerLogger(logger log.Logger) WorkerOption

func WithWorkerRePushDuration

func WithWorkerRePushDuration(d time.Duration) WorkerOption

WithWorkerRePushDuration configures when enrollments should be sent APNs pushes. This is the duration an enrollment ID has not received a response for an MDM command.

type WorkflowFinder

type WorkflowFinder interface {
	Workflow(name string) workflow.Workflow
}

Directories

Path Synopsis
Package http contains HTTP handlers that work with the NanoCMD engine.
Package http contains HTTP handlers that work with the NanoCMD engine.
Package storage defines types and primitives for workflow engine storage backends.
Package storage defines types and primitives for workflow engine storage backends.
diskv
Package diskv implements an engine storage backend using the diskv key-value store.
Package diskv implements an engine storage backend using the diskv key-value store.
inmem
Package inmem implements an engine storage backend using the a map-based key-value store.
Package inmem implements an engine storage backend using the a map-based key-value store.
kv
Package kv implements a workflow engine storage backend using a key-value interface.
Package kv implements a workflow engine storage backend using a key-value interface.

Jump to

Keyboard shortcuts

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