anbaric-state-machine 1.16.2 → 1.16.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/src/StateMachine.ts +8 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "anbaric-state-machine",
|
|
3
|
-
"version": "1.16.
|
|
3
|
+
"version": "1.16.3",
|
|
4
4
|
"description": "This is the state machine library that one can use to add state management to an application. It will, by default, be locally runnable but can deployed to the Anbaric Cloud via the CLI",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "chris@anbaric.ai",
|
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
"typescript": "^7.0.2"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"anbaric-impl-cloud": "^1.16.
|
|
19
|
-
"anbaric-tsapi": "^1.16.
|
|
18
|
+
"anbaric-impl-cloud": "^1.16.3",
|
|
19
|
+
"anbaric-tsapi": "^1.16.3"
|
|
20
20
|
},
|
|
21
21
|
"files": [
|
|
22
22
|
"src"
|
package/src/StateMachine.ts
CHANGED
|
@@ -33,20 +33,24 @@ class StateMachine {
|
|
|
33
33
|
|
|
34
34
|
constructor(workflowId : string, states : Array<State>, startState? : string, dataSchema : Array<PropertyDefinition> = [], persistence : JobPersistence = JobPersistenceFactory.instance(), queue : Queue = QueueFactory.instance(), sameStateDelayMs : number = 5 * 60_000, auditor : Auditor = AuditorFactory.instance()) {
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
// A deployed app namespaces its state machines by app id, so the same
|
|
37
|
+
// workflow id used in two different apps never collides. Run locally
|
|
38
|
+
// (no app id in the environment) the id is used as given.
|
|
39
|
+
const appId = process.env.ANBARIC_APP_ID;
|
|
40
|
+
this.workflowId = appId ? `${appId}/${workflowId}` : workflowId;
|
|
37
41
|
this.states = new Map(states.map(state => [state.id, state]));
|
|
38
42
|
this.startState = startState ?? states[0].id;
|
|
39
43
|
this.dataSchema = new Map(dataSchema.map(property => [property.id, property]));
|
|
40
44
|
this.persistence = persistence;
|
|
41
45
|
this.queue = queue;
|
|
42
|
-
this.machineActor = new Code(workflowId, "state-machine");
|
|
46
|
+
this.machineActor = new Code(this.workflowId, "state-machine");
|
|
43
47
|
this.sameStateDelayMs = sameStateDelayMs;
|
|
44
48
|
this.auditor = auditor;
|
|
45
49
|
|
|
46
50
|
this.consumer = ConsumerFactory.instance(queue)
|
|
47
|
-
this.consumer.subscribe(workflowId, jobId => this.progressJob(jobId));
|
|
51
|
+
this.consumer.subscribe(this.workflowId, jobId => this.progressJob(jobId));
|
|
48
52
|
|
|
49
|
-
void this.auditor.audit("state-machine", workflowId, SystemActor.actor, ["INITIALIZE"],
|
|
53
|
+
void this.auditor.audit("state-machine", this.workflowId, SystemActor.actor, ["INITIALIZE"],
|
|
50
54
|
"State machine initialised", this.describe()).catch(() => {});
|
|
51
55
|
}
|
|
52
56
|
|