engine

package module
v0.0.0-...-651fe2a Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2020 License: BSD-2-Clause Imports: 35 Imported by: 0

README

Workflow Engine

builds.sr.ht status

This is a Workflow Engine framework written in Go. You can read the documentation book for more details.

Documentation

Index

Constants

View Source
const (
	CACHE_DIR = "./cache"
)
View Source
const (
	DATE_FORMAT = "2006-01-02 15:04:05" // MySQL format
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Channel

type Channel struct {
	ChannelID          string         `json:"channel_id"`
	ChannelDescription string         `json:"channel_description,omitempty"`
	ServiceID          string         `json:"service_id"`
	Initiators         []string       `json:"initiators"` // List of systems which can initiate this workflow
	FileName           string         `json:"-"`
	FileHash           string         `json:"-"` // sha1 of the struct
	Steps              []WorkflowStep `json:"steps"`
}

Channel represents a single workflow channel. This is in a separate file.

type CommitObject

type CommitObject struct {
	Name      string            `json:"name"`
	Type      string            `json:"type"`
	Variables map[string]string `json:"variables"`
}

CommitObject represents a database object which can be used in the Commit stage of a WorkflowStep.

type Criteria

type Criteria struct {
	CriteriaName string      `json:"name"`
	Expression   string      `json:"expression"`
	CompiledExpr *vm.Program `json:"-"`
	FailMessage  string      `json:"fail_message,omitempty"`
}

Criteria represents a criteria required for a step to continue.

type CriteriaType

type CriteriaType int

CriteriaType is the type of criteria in a workflow step. There are criterion which must be true before a step can be actualised, and criterion which must be true before a step is complete.

const (
	ExecutionCriteria CriteriaType = iota + 1
	FinalisationCriteria
)

type DBCount

type DBCount func(table string, query string, preparedArgs ...interface{}) int64

DBCount is the type of the function which returns the count of rows which matches the query from the external database.

type DBDelete

type DBDelete func(table string, id interface{}) error

type DBDeleteObj

type DBDeleteObj func(object interface{}) error

type DBExists

type DBExists func(table string, query string, preparedArgs ...interface{}) bool

DBExists is the type of the function which returns whether a row exists in the database which matches the query in the external database.

type DBFirst

type DBFirst func(table string, query string, preparedArgs ...interface{}) interface{}

DBFirst is the type of the function which returns the first row which matches the query from the external database.

type DBInsert

type DBInsert func(object interface{}) error

type DBQuery

type DBQuery func(table string, query string, preparedArgs ...interface{}) interface{}

DBQuery is the type of the function which returns the all the rows which matches the query from the external database.

type DBUpdate

type DBUpdate func(id interface{}, object interface{}) error

type DBUpdateCols

type DBUpdateCols func(id interface{}, object interface{}, cols ...string) error

type DatabaseOpts

type DatabaseOpts struct {
	Type                 DatabaseType
	Host, User, Password string
	Database             string
	SSLMode              string // TLS mode for MySQL, SSLMode for PostgreSQL
	Path                 string // for SQLite only
}

DatabaseOpts represents a database connection credentials.

type DatabaseType

type DatabaseType int

DatabaseType represents a database driver.

const (
	SQLite DatabaseType = iota
	MySQL
	PostgreSQL
)

type Engine

type Engine struct {
	Options         EngineOpts
	EngineDB        *xorm.Engine
	ExtDB           *xorm.Engine
	SchemasModified bool
	Schemas         map[string]Schema
	Services        []Service
	DevMode         bool
}

Engine represents a workflow engine.

func NewEngine

func NewEngine(opt EngineOpts) (e *Engine, err error)

NewEngine creates a new Workflow Engine based on the given options. Returns an error if it couldn't connect to any of the databases, or when there is an error loading the workflow files from disk.

func SetupTestEngine

func SetupTestEngine() *Engine

func (*Engine) RegisterSchema

func (e *Engine) RegisterSchema(value Schema)

RegisterSchema adds an GORM structure to the list of available schemas in the engine, so it could be used in the workflows. These relate to the ExtDatabase given in the EngineOpts.

func (*Engine) Run

func (e *Engine) Run()

Run runs the HTTP server which hosts the JSON API and dashboard.

func (*Engine) RunWebInterface

func (e *Engine) RunWebInterface()

func (*Engine) ServeHTTP

func (e *Engine) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP runs the HTTP server which hosts the JSON API.

func (*Engine) ValidateWorkflows

func (e *Engine) ValidateWorkflows() error

ValidateWorkflows goes through each workflow, and make sure all database-related fields, actions, etc can be reflected. This must only be run once all schemas are registered.

type EngineOpts

type EngineOpts struct {
	EngineDatabase  DatabaseOpts
	ExtDatabase     DatabaseOpts
	WorkflowDirPath string
	Users           []User
	APIPort         int
	AdminPort       int
	DashboardKey    string
	APITokens       []string
}

EngineOpts represents a workflow engine options.

type IDField

type IDField struct {
	IDInt int64
	IDStr string
	IsStr bool
}

type PullData

type PullData struct {
	Name   string `json:"name"`
	URL    string `json:"url"`
	Params map[string]string
}

type Schema

type Schema interface{}

type Service

type Service struct {
	ServiceID   string    `json:"service_id"`
	Description string    `json:"description"`
	Category    string    `json:"category"`
	FileName    string    `json:"-"`
	FileHash    string    `json:"-"` // sha1 of the struct
	Channels    []Channel `json:"-"` // We load these from separate files
}

Service represents a category of workflows. This is in a separate file.

type StepComplete

type StepComplete func(step string) bool

type User

type User struct {
	UserID     string
	Group      string
	Department string
}

User represents a workflow user which tasks will be designate to.

type WorkflowStep

type WorkflowStep struct {
	StepID string `json:"step_id"`
	Status string `json:"status"` // Status description of this step
	// Page which will show to the end-user, does not affect the engine
	Page           string         `json:"page"`
	PostTo         []string       `json:"post_to"`
	DataIn         []string       `json:"data_in"`
	DataOut        []string       `json:"data_out"`
	PullData       []PullData     `json:"pull_data"`
	CriteriaExec   []Criteria     `json:"criteria_execution"`
	CriteriaFinal  []Criteria     `json:"criteria_finalisation"`
	CommitObjects  []CommitObject `json:"commit_objects"`
	Commit         []string       `json:"commit"`
	EndApplication bool           `json:"end_application"`
}

WorkflowStep represents a step.

Directories

Path Synopsis
Package public generated by go-bindata.// sources: public/bindata.go public/css/main.css public/css/normalize-8.0.1.min.css public/img/logo.png
Package public generated by go-bindata.// sources: public/bindata.go public/css/main.css public/css/normalize-8.0.1.min.css public/img/logo.png
Package templates generated by go-bindata.// sources: templates/base/footer.tmpl templates/base/head.tmpl templates/bindata.go templates/channel.tmpl templates/dash.tmpl templates/edit-channel.tmpl templates/edit-service.tmpl templates/edit-step.tmpl templates/errors.tmpl templates/index.tmpl templates/login.tmpl templates/new-channel.tmpl templates/new-commit-obj.tmpl templates/new-criteria.tmpl templates/new-service.tmpl templates/new-step.tmpl templates/partials/flash.tmpl templates/service.tmpl templates/step.tmpl
Package templates generated by go-bindata.// sources: templates/base/footer.tmpl templates/base/head.tmpl templates/bindata.go templates/channel.tmpl templates/dash.tmpl templates/edit-channel.tmpl templates/edit-service.tmpl templates/edit-step.tmpl templates/errors.tmpl templates/index.tmpl templates/login.tmpl templates/new-channel.tmpl templates/new-commit-obj.tmpl templates/new-criteria.tmpl templates/new-service.tmpl templates/new-step.tmpl templates/partials/flash.tmpl templates/service.tmpl templates/step.tmpl

Jump to

Keyboard shortcuts

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