orbits

@wbce/orbits / Exports / Workflow

Class: Workflow

Action is the class to structure actions Extends this class to build new actions behaviours. You can read more here :

Hierarchy

Table of contents

Constructors

Properties

Accessors

Methods

Constructors

constructor

new Workflow()

Overrides

Action.constructor

Defined in

src/workflow-manager.ts:44

Properties

IArgument

IArgument: Object

Interface of the argument of the action

Inherited from

Action.IArgument

Defined in

src/action-manager.ts:75


IBag

IBag: Object

Interface of the bag of the action

Type declaration

Name Type
actions { [key: string]: { result: any ; state: ActionState }; }
currentStepIndex? number
isRollBackPossible boolean
nTimesCurrentStep number
oldResult any
stepsHistory number[]

Overrides

Action.IBag

Defined in

src/workflow-manager.ts:30


IResult

IResult: Object

Interface of the result of the action

Inherited from

Action.IResult

Defined in

src/action-manager.ts:88


RollBackAction

RollBackAction: typeof Action = RollBackAction

The action that rollback this action.

Inherited from

Action.RollBackAction

Defined in

src/action-manager.ts:665


RollBackWorkflow

RollBackWorkflow: typeof RevertWorkflow = RevertWorkflow

Overrides

Action.RollBackWorkflow

Defined in

src/workflow-manager.ts:384


app

app: ActionApp

Inherited from

Action.app

Defined in

src/action-manager.ts:31


cronDefaultSettings

cronDefaultSettings: Object

Configure the frequence in which a cron will cause the

Link

Action.resume method. You can also dinamically modify the dbDoc.cronActivity property to modify the call to a cron.

Type declaration

Name Type
activityFrequence number

Inherited from

Action.cronDefaultSettings

Defined in

src/action-manager.ts:65


dBSession

Optional dBSession: ClientSession

Defined in

src/workflow-manager.ts:24


dbDoc

dbDoc: ActionSchemaInterface<{}, { actions: { [key: string]: { result: any ; state: ActionState }; } ; currentStepIndex?: number ; isRollBackPossible: boolean ; nTimesCurrentStep: number ; oldResult: any ; stepsHistory: number[] }, {}>

The database document of this action.

Inherited from

Action.dbDoc

Defined in

src/action-manager.ts:95


defaultDelay

defaultDelay: number = Infinity

Shorcut to

Link

Action.defaultDelays[ActionState.IN_PROGRESS]

Overrides

Action.defaultDelay

Defined in

src/workflow-manager.ts:21


defaultDelays

defaultDelays: Object

For the state ActionState.EXECUTING_MAIN and ActionState.IN_PROGRESS, this object configure the time after which, if no change happened, an action is considered in error. For example, an action can only be in the ActionState.IN_PROGRESS state for as long as defaultDelays[ActionState.IN_PROGRESS] time.

Default Value

You should modify this if your actions have longer timeouts.

Type declaration

Name Type
1 number
2 number

Inherited from

Action.defaultDelays

Defined in

src/action-manager.ts:53


docsToSaveAtStepStart

docsToSaveAtStepStart: Document<any, any, any>[] = []

Defined in

src/workflow-manager.ts:26


executor

Optional executor: Executor

Specify an executor in which all actions of this class will run.

Inherited from

Action.executor

Defined in

src/action-manager.ts:29


isInitialised

isInitialised: boolean = false

Inherited from

Action.isInitialised

Defined in

src/action-manager.ts:346


steps

steps: Step[] = []

Defined in

src/workflow-manager.ts:28


permanentRef

Static permanentRef: string

The id of the action we store in database. This should be a permanent id that designates your instance. See :

Inherited from

Action.permanentRef

Defined in

src/action-manager.ts:24

Accessors

_id

get _id(): this["dbDoc"]["_id"]

Returns

this["dbDoc"]["_id"]

Inherited from

Action._id

Defined in

src/action-manager.ts:142


argument

get argument(): this["dbDoc"]["argument"]

Returns

this["dbDoc"]["argument"]

Inherited from

Action.argument

Defined in

src/action-manager.ts:106

set argument(argument): void

Parameters

Name Type
argument this["dbDoc"]["argument"]

Returns

void

Inherited from

Action.argument

Defined in

src/action-manager.ts:110


bag

get bag(): this["dbDoc"]["bag"]

Returns

this["dbDoc"]["bag"]

Inherited from

Action.bag

Defined in

src/action-manager.ts:97

set bag(bag): void

Parameters

Name Type
bag this["dbDoc"]["bag"]

Returns

void

Inherited from

Action.bag

Defined in

src/action-manager.ts:101


cronActivity

get cronActivity(): this["dbDoc"]["cronActivity"]

Returns

this["dbDoc"]["cronActivity"]

Inherited from

Action.cronActivity

Defined in

src/action-manager.ts:133

set cronActivity(cronActivity): void

Parameters

Name Type
cronActivity this["dbDoc"]["cronActivity"]

Returns

void

Inherited from

Action.cronActivity

Defined in

src/action-manager.ts:137


isRollBackPossible

get isRollBackPossible(): boolean

Returns

boolean

Overrides

Action.isRollBackPossible

Defined in

src/workflow-manager.ts:370


repeat

get repeat(): this["dbDoc"]["repeat"]

Returns

this["dbDoc"]["repeat"]

Inherited from

Action.repeat

Defined in

src/action-manager.ts:124

set repeat(repeat): void

Parameters

Name Type
repeat this["dbDoc"]["repeat"]

Returns

void

Inherited from

Action.repeat

Defined in

src/action-manager.ts:128


result

get result(): this["dbDoc"]["result"]

Returns

this["dbDoc"]["result"]

Inherited from

Action.result

Defined in

src/action-manager.ts:115

set result(result): void

Parameters

Name Type
result this["dbDoc"]["result"]

Returns

void

Inherited from

Action.result

Defined in

src/action-manager.ts:119

Methods

_resume

_resume(): any

The function resumes the action by calling the appropriate function depending on the current state of the action. It doesn’t take into account the executor.

Returns

any

A promise. You can not rely on this to know when an action is finished.

Inherited from

Action._resume

Defined in

src/action-manager.ts:437


activityLogs

activityLogs(options): any[] | Promise<any[]>

Parameters

Name Type
options any

Returns

any[] | Promise<any[]>

Inherited from

Action.activityLogs

Defined in

src/action-manager.ts:561


catch

catch(cb, opts?): Workflow

Parameters

Name Type
cb (…args: any[]) => void | Action | Action[] | Promise<void | Action | Action[]>
opts? Object
opts.retry number

Returns

Workflow

Defined in

src/workflow-manager.ts:58


changeState

changeState(actionState): Promise<void>

Parameters

Name Type
actionState ActionState

Returns

Promise<void>

Inherited from

Action.changeState

Defined in

src/action-manager.ts:478


createRollBackWorkflow

createRollBackWorkflow(): Workflow

Returns

Workflow

The workflow that wait for the end of this action if needed and then rollback this action.

Inherited from

Action.createRollBackWorkflow

Defined in

src/action-manager.ts:673


declareActionEnd

declareActionEnd(dbDoc): void

Parameters

Name Type
dbDoc ActionSchemaInterface<any, any, any>

Returns

void

Defined in

src/workflow-manager.ts:173


declareActionStart

declareActionStart(dbDoc): void

Parameters

Name Type
dbDoc ActionSchemaInterface<any, any, any>

Returns

void

Defined in

src/workflow-manager.ts:160


define

define(): void | Promise<void>

Returns

void | Promise<void>

Defined in

src/workflow-manager.ts:313


endStep

endStep(): Promise<ActionState>

Returns

Promise<ActionState>

Defined in

src/workflow-manager.ts:286


finally

finally(cb, opts?): Workflow

Parameters

Name Type
cb (…args: any[]) => void | Action | Action[] | Promise<void | Action | Action[]>
opts? Object
opts.retry number

Returns

Workflow

Defined in

src/workflow-manager.ts:67


getLogs

getLogs(options?): Promise<any[]>

Parameters

Name Type
options Object
options.endTime? number

Returns

Promise<any[]>

Inherited from

Action.getLogs

Defined in

src/action-manager.ts:565


getNextStep

getNextStep(): Promise<void | Action | Action[]>

Returns

Promise<void | Action | Action[]>

Defined in

src/workflow-manager.ts:184


goTo

goTo(name, onState): Workflow

Parameters

Name Type
name string
onState ActionState

Returns

Workflow

Defined in

src/workflow-manager.ts:138


goToStep

goToStep(name): ResolveAction

Parameters

Name Type
name string

Returns

ResolveAction

Defined in

src/workflow-manager.ts:130


init

init(): Promise<any>

Initialize the action from the action stored in the database.

Example

In order to not store secrets in the database, you can set a vault id in the argument and retrieve the secret at the initialization of the action

Example

You cannot store class object on the database. If your action use complex object, they can be initialized here

Returns

Promise<any>

Inherited from

Action.init

Defined in

src/action-manager.ts:285


initialisation

initialisation(): Promise<void>

Returns

Promise<void>

Overrides

Action.initialisation

Defined in

src/workflow-manager.ts:304


internalLog

internalLog(message): void

Parameters

Name Type
message string

Returns

void

Inherited from

Action.internalLog

Defined in

src/action-manager.ts:606


internalLogError

internalLogError(err): void

Parameters

Name Type
err Error

Returns

void

Inherited from

Action.internalLogError

Defined in

src/action-manager.ts:615


isActionActive

isActionActive(action): boolean

Parameters

Name Type
action Action

Returns

boolean

Defined in

src/workflow-manager.ts:156


main

main(): Promise<unknown>

This method should launched the main action processus It is called only one time. It returns a state value.

Returns

Promise<unknown>

Overrides

Action.main

Defined in

src/workflow-manager.ts:317


name

name(name): Workflow

Parameters

Name Type
name string

Returns

Workflow

Defined in

src/workflow-manager.ts:122


next

next(cb, opts?): Workflow

Parameters

Name Type
cb (…args: any[]) => void | Action | Action[] | Promise<void | Action | Action[]>
opts? Object
opts.retry number

Returns

Workflow

Defined in

src/workflow-manager.ts:49


onErrorGoTo

onErrorGoTo(name): Workflow

Parameters

Name Type
name string

Returns

Workflow

Defined in

src/workflow-manager.ts:151


onStateNotification

onStateNotification(actionState?): Promise<void>

Parameters

Name Type Default value
actionState ActionState ActionState.UNKNOW

Returns

Promise<void>

Inherited from

Action.onStateNotification

Defined in

src/action-manager.ts:487


onSuccessGoTo

onSuccessGoTo(name): Workflow

Parameters

Name Type
name string

Returns

Workflow

Defined in

src/workflow-manager.ts:146


registerDocToSaveAtStepStart

registerDocToSaveAtStepStart(doc): void

Parameters

Name Type
doc Document<any, any, any>

Returns

void

Defined in

src/workflow-manager.ts:300


resume

resume(): Promise<unknown>

The function resumes the action by calling the appropriate executor if needed and then by calling the appropriate function depending on the current state of the action

Returns

Promise<unknown>

A promise. You can not rely on this to know when an action is finished.

Inherited from

Action.resume

Defined in

src/action-manager.ts:414


resyncWithDb

resyncWithDb(): Promise<void>

This function will update the current instance of the model with the latest data from the database

Returns

Promise<void>

A promise that resolves when the last document version has be loaded

Inherited from

Action.resyncWithDb

Defined in

src/action-manager.ts:212


rollBack

rollBack(): Promise<ActionState>

Shortcut to configure a rollback. Will be encapsulated in a larger action

Returns

Promise<ActionState>

Inherited from

Action.rollBack

Defined in

src/action-manager.ts:643


rollBackWatcher

rollBackWatcher(): Promise<UNKNOW | SUCCESS>

Shortcut to configure the watcher of the rollback Action

Returns

Promise<UNKNOW | SUCCESS>

Inherited from

Action.rollBackWatcher

Defined in

src/action-manager.ts:651


rollback

rollback(cb, opts?): Workflow

Parameters

Name Type
cb (…args: any[]) => void | Action | Action[] | Promise<void | Action | Action[]>
opts? Object
opts.retry number

Returns

Workflow

Defined in

src/workflow-manager.ts:113


save

save(): Promise<ActionSchemaInterface<{}, { actions: { [key: string]: { result: any ; state: ActionState }; } ; currentStepIndex?: number ; isRollBackPossible: boolean ; nTimesCurrentStep: number ; oldResult: any ; stepsHistory: number[] }, {}>>

Returns

Promise<ActionSchemaInterface<{}, { actions: { [key: string]: { result: any ; state: ActionState }; } ; currentStepIndex?: number ; isRollBackPossible: boolean ; nTimesCurrentStep: number ; oldResult: any ; stepsHistory: number[] }, {}>>

Inherited from

Action.save

Defined in

src/action-manager.ts:146


setArgument

setArgument(args): void

It takes an object of type IArgument and sets the argument that will be stored in the database. Once set, the argument of an action should not be modified.

Parameters

Name Type Description
args Object The arguments that you want to set.

Returns

void

Inherited from

Action.setArgument

Defined in

src/action-manager.ts:295


setFilter

setFilter(filter): void

To make filtering easier, you can pass filter to an action. This filters are stored on the database with the filter property and allow you to search for an action or a group of actions

Parameters

Name Type
filter Object

Returns

void

Inherited from

Action.setFilter

Defined in

src/action-manager.ts:319


setRepeat

setRepeat(opts): void

Configure the number of times an action is repeated.

Parameters

Name Type
opts Object
opts.4? number
opts.5? number

Returns

void

Inherited from

Action.setRepeat

Defined in

src/action-manager.ts:305


setResult

setResult(result): void

Set the result of the action.

Parameters

Name Type
result Object

Returns

void

Inherited from

Action.setResult

Defined in

src/action-manager.ts:329


startStep

startStep(): Promise<unknown>

Returns

Promise<unknown>

Defined in

src/workflow-manager.ts:226


watcher

watcher(): Promise<ActionState>

This method should calculate the current state of the action. It is called :

Returns

Promise<ActionState>

Overrides

Action.watcher

Defined in

src/workflow-manager.ts:332


constructFromDb

Static constructFromDb(actionDb): Action

Permit to construct an action from a document stored in the database.

Parameters

Name Type Description
actionDb ActionSchemaInterface<any, any, any> a document coming from the database

Returns

Action

an action for which dbDoc property is equal to actionDb

Inherited from

Action.constructFromDb

Defined in

src/action-manager.ts:199


reject

Static reject(result?): RejectAction

static reject(result?){

The above function is a static function that returns a new RejectAction object. The function takes an optional parameter called result

Parameters

Name Type Description
result? any The result of the action.

Returns

RejectAction

A new instance of the RejectAction class.

Inherited from

Action.reject

Defined in

src/action-manager.ts:243


resolve

Static resolve(result?): ResolveAction

It returns a new ResolveAction object.

Parameters

Name Type Description
result? any The result of the action.

Returns

ResolveAction

A new instance of the ResolveAction class.

Inherited from

Action.resolve

Defined in

src/action-manager.ts:229