@wbce/orbits / Exports / RevertWorkflow
Action is the class to structure actions Extends this class to build new actions behaviours. You can read more here :
Name | Type |
---|---|
WorkflowToRevert |
extends Workflow |
↳ RevertWorkflow
• new RevertWorkflow<WorkflowToRevert
>()
Name | Type |
---|---|
WorkflowToRevert |
extends Workflow <WorkflowToRevert > |
• IArgument: Object
Interface of the argument of the action
Name | Type |
---|---|
actionId |
string |
• IBag: Object
Interface of the bag of the action
Name | Type |
---|---|
actions |
{ [key: string] : { result : any ; state : ActionState }; } |
currentStepIndex? |
number |
isRollBackPossible |
boolean |
nTimesCurrentStep |
number |
oldResult |
any |
stepsHistory |
number [] |
• IResult: Object
Interface of the result of the action
• RollBackAction: typeof Action
= RollBackAction
The action that rollback this action.
• RollBackWorkflow: typeof RevertWorkflow
= RevertWorkflow
• app: ActionApp
• 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.
Name | Type |
---|---|
activityFrequence |
number |
• Optional
dBSession: ClientSession
• dbDoc: ActionSchemaInterface
<{ actionId
: string
}, { actions
: { [key: string]
: { result
: any
; state
: ActionState
}; } ; currentStepIndex?
: number
; isRollBackPossible
: boolean
; nTimesCurrentStep
: number
; oldResult
: any
; stepsHistory
: number
[] }, {}>
The database document of this action.
• defaultDelay: number
= Infinity
Shorcut to
Link
Action.defaultDelays[ActionState.IN_PROGRESS]
• 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.
Name | Type |
---|---|
1 |
number |
2 |
number |
• docsToSaveAtStepStart: Document
<any
, any
, any
>[] = []
Workflow.docsToSaveAtStepStart
• Optional
executor: Executor
Specify an executor in which all actions of this class will run.
• isInitialised: boolean
= false
• oldAction: WorkflowToRevert
• steps: Step
[] = []
▪ Static
permanentRef: string
The id of the action we store in database. This should be a permanent id that designates your instance. See :
• get
_id(): this
["dbDoc"
]["_id"
]
this
["dbDoc"
]["_id"
]
Workflow._id
• get
argument(): this
["dbDoc"
]["argument"
]
this
["dbDoc"
]["argument"
]
Workflow.argument
• set
argument(argument
): void
Name | Type |
---|---|
argument |
this ["dbDoc" ]["argument" ] |
void
Workflow.argument
• get
bag(): this
["dbDoc"
]["bag"
]
this
["dbDoc"
]["bag"
]
Workflow.bag
• set
bag(bag
): void
Name | Type |
---|---|
bag |
this ["dbDoc" ]["bag" ] |
void
Workflow.bag
• get
cronActivity(): this
["dbDoc"
]["cronActivity"
]
this
["dbDoc"
]["cronActivity"
]
Workflow.cronActivity
• set
cronActivity(cronActivity
): void
Name | Type |
---|---|
cronActivity |
this ["dbDoc" ]["cronActivity" ] |
void
Workflow.cronActivity
• get
isRollBackPossible(): boolean
boolean
Workflow.isRollBackPossible
• get
repeat(): this
["dbDoc"
]["repeat"
]
this
["dbDoc"
]["repeat"
]
Workflow.repeat
• set
repeat(repeat
): void
Name | Type |
---|---|
repeat |
this ["dbDoc" ]["repeat" ] |
void
Workflow.repeat
• get
result(): this
["dbDoc"
]["result"
]
this
["dbDoc"
]["result"
]
Workflow.result
• set
result(result
): void
Name | Type |
---|---|
result |
this ["dbDoc" ]["result" ] |
void
Workflow.result
▸ _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.
any
A promise. You can not rely on this to know when an action is finished.
▸ activityLogs(options
): any
[] | Promise
<any
[]>
Name | Type |
---|---|
options |
any |
any
[] | Promise
<any
[]>
▸ catch(cb
, opts?
): RevertWorkflow
<WorkflowToRevert
>
Name | Type |
---|---|
cb |
(…args : any []) => void | Action | Action [] | Promise <void | Action | Action []> |
opts? |
Object |
opts.retry |
number |
RevertWorkflow
<WorkflowToRevert
>
▸ changeState(actionState
): Promise
<void
>
Name | Type |
---|---|
actionState |
ActionState |
Promise
<void
>
▸ createRollBackWorkflow(): Workflow
The workflow that wait for the end of this action if needed and then rollback this action.
Workflow.createRollBackWorkflow
▸ declareActionEnd(dbDoc
): void
Name | Type |
---|---|
dbDoc |
ActionSchemaInterface <any , any , any > |
void
▸ declareActionStart(dbDoc
): void
Name | Type |
---|---|
dbDoc |
ActionSchemaInterface <any , any , any > |
void
▸ define(): Promise
<void
>
Promise
<void
>
▸ endStep(): Promise
<ActionState
>
Promise
<ActionState
>
▸ finally(cb
, opts?
): RevertWorkflow
<WorkflowToRevert
>
Name | Type |
---|---|
cb |
(…args : any []) => void | Action | Action [] | Promise <void | Action | Action []> |
opts? |
Object |
opts.retry |
number |
RevertWorkflow
<WorkflowToRevert
>
▸ getLogs(options?
): Promise
<any
[]>
Name | Type |
---|---|
options |
Object |
options.endTime? |
number |
Promise
<any
[]>
▸ getNextStep(): Promise
<void
| Action
| Action
[]>
Promise
<void
| Action
| Action
[]>
▸ goTo(name
, onState
): RevertWorkflow
<WorkflowToRevert
>
Name | Type |
---|---|
name |
string |
onState |
ActionState |
RevertWorkflow
<WorkflowToRevert
>
▸ goToStep(name
): ResolveAction
Name | Type |
---|---|
name |
string |
▸ init(): Promise
<void
>
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
Promise
<void
>
▸ initialisation(): Promise
<void
>
Promise
<void
>
▸ internalLog(message
): void
Name | Type |
---|---|
message |
string |
void
▸ internalLogError(err
): void
Name | Type |
---|---|
err |
Error |
void
▸ isActionActive(action
): boolean
Name | Type |
---|---|
action |
Action |
boolean
▸ main(): Promise
<unknown
>
This method should launched the main action processus It is called only one time. It returns a state value.
Promise
<unknown
>
▸ name(name
): RevertWorkflow
<WorkflowToRevert
>
Name | Type |
---|---|
name |
string |
RevertWorkflow
<WorkflowToRevert
>
▸ next(cb
, opts?
): RevertWorkflow
<WorkflowToRevert
>
Name | Type |
---|---|
cb |
(…args : any []) => void | Action | Action [] | Promise <void | Action | Action []> |
opts? |
Object |
opts.retry |
number |
RevertWorkflow
<WorkflowToRevert
>
▸ onErrorGoTo(name
): RevertWorkflow
<WorkflowToRevert
>
Name | Type |
---|---|
name |
string |
RevertWorkflow
<WorkflowToRevert
>
▸ onStateNotification(actionState?
): Promise
<void
>
Name | Type | Default value |
---|---|---|
actionState |
ActionState |
ActionState.UNKNOW |
Promise
<void
>
▸ onSuccessGoTo(name
): RevertWorkflow
<WorkflowToRevert
>
Name | Type |
---|---|
name |
string |
RevertWorkflow
<WorkflowToRevert
>
▸ registerDocToSaveAtStepStart(doc
): void
Name | Type |
---|---|
doc |
Document <any , any , any > |
void
Workflow.registerDocToSaveAtStepStart
▸ 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
Promise
<unknown
>
A promise. You can not rely on this to know when an action is finished.
▸ resyncWithDb(): Promise
<void
>
This function will update the current instance of the model with the latest data from the database
Promise
<void
>
A promise that resolves when the last document version has be loaded
▸ revertChildrenAction(stepIndex
): Promise
<Workflow
[]>
Name | Type |
---|---|
stepIndex |
any |
Promise
<Workflow
[]>
▸ rollBack(): Promise
<ActionState
>
Shortcut to configure a rollback. Will be encapsulated in a larger action
Promise
<ActionState
>
▸ rollBackWatcher(): Promise
<UNKNOW
| SUCCESS
>
Shortcut to configure the watcher of the rollback Action
▸ rollback(cb
, opts?
): RevertWorkflow
<WorkflowToRevert
>
Name | Type |
---|---|
cb |
(…args : any []) => void | Action | Action [] | Promise <void | Action | Action []> |
opts? |
Object |
opts.retry |
number |
RevertWorkflow
<WorkflowToRevert
>
▸ save(): Promise
<ActionSchemaInterface
<{ actionId
: string
}, { actions
: { [key: string]
: { result
: any
; state
: ActionState
}; } ; currentStepIndex?
: number
; isRollBackPossible
: boolean
; nTimesCurrentStep
: number
; oldResult
: any
; stepsHistory
: number
[] }, {}>>
Promise
<ActionSchemaInterface
<{ actionId
: string
}, { actions
: { [key: string]
: { result
: any
; state
: ActionState
}; } ; currentStepIndex?
: number
; isRollBackPossible
: boolean
; nTimesCurrentStep
: number
; oldResult
: any
; stepsHistory
: number
[] }, {}>>
▸ 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.
Name | Type | Description |
---|---|---|
args |
Object |
The arguments that you want to set. |
args.actionId |
string |
- |
void
▸ 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
Name | Type |
---|---|
filter |
Object |
void
▸ setRepeat(opts
): void
Configure the number of times an action is repeated.
Name | Type |
---|---|
opts |
Object |
opts.4? |
number |
opts.5? |
number |
void
▸ setResult(result
): void
Set the result of the action.
Name | Type |
---|---|
result |
Object |
void
▸ startStep(): Promise
<unknown
>
Promise
<unknown
>
▸ watcher(): Promise
<ActionState
>
This method should calculate the current state of the action. It is called :
Promise
<ActionState
>
▸ Static
constructFromDb(actionDb
): Action
Permit to construct an action from a document stored in the database.
Name | Type | Description |
---|---|---|
actionDb |
ActionSchemaInterface <any , any , any > |
a document coming from the database |
an action for which dbDoc property is equal to actionDb
▸ 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
Name | Type | Description |
---|---|---|
result? |
any |
The result of the action. |
A new instance of the RejectAction class.
▸ Static
resolve(result?
): ResolveAction
It returns a new ResolveAction object.
Name | Type | Description |
---|---|---|
result? |
any |
The result of the action. |
A new instance of the ResolveAction class.