@reventlessdev/reventless-core 3.0.0-alpha.334 → 3.0.0-alpha.336
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/CHANGELOG.md +23 -0
- package/package.json +6 -6
- package/src/CommandSent.res +10 -0
- package/src/CommandSent.res.mjs +8 -0
- package/src/admin/Platform_I18n.res +112 -0
- package/src/admin/Platform_I18n.res.mjs +115 -0
- package/src/components/Aggregate/Aggregate_Callback.res +3 -0
- package/src/components/Aggregate/Aggregate_Callback.res.mjs +3 -3
- package/src/components/AutomationSlice/AutomationSlice.res +3 -0
- package/src/components/AutomationSlice/AutomationSlice_Builder.res +24 -8
- package/src/components/AutomationSlice/AutomationSlice_Builder.res.mjs +109 -102
- package/src/components/AutomationSlice/AutomationSlice_Callback.res +75 -8
- package/src/components/AutomationSlice/AutomationSlice_Callback.res.mjs +58 -7
- package/src/components/CommandGenerator/CommandGenerator_Callback.res.mjs +1 -1
- package/src/components/CommandTopic/CommandTopic.res.mjs +9 -0
- package/src/components/CommandTopic/CommandTopic_Helpers.res +118 -33
- package/src/components/CommandTopic/CommandTopic_Helpers.res.mjs +137 -22
- package/src/components/Dcb/Dcb_Builder.res +16 -0
- package/src/components/Dcb/Dcb_Builder.res.mjs +6 -3
- package/src/components/InboundTranslationSlice/InboundTranslationSlice.res +3 -0
- package/src/components/InboundTranslationSlice/InboundTranslationSlice_Builder.res +17 -6
- package/src/components/InboundTranslationSlice/InboundTranslationSlice_Builder.res.mjs +46 -41
- package/src/components/InboundTranslationSlice/InboundTranslationSlice_Callback.res +37 -8
- package/src/components/InboundTranslationSlice/InboundTranslationSlice_Callback.res.mjs +33 -13
- package/src/components/InboundTranslationSlice/InboundTranslationSlice_Webhook.res +3 -0
- package/src/components/InboundTranslationSlice/InboundTranslationSlice_Webhook.res.mjs +14 -2
- package/src/components/OutboundTranslationSlice/OutboundTranslationSlice.res +3 -0
- package/src/components/OutboundTranslationSlice/OutboundTranslationSlice_Builder.res +30 -9
- package/src/components/OutboundTranslationSlice/OutboundTranslationSlice_Builder.res.mjs +10 -5
- package/src/components/OutboundTranslationSlice/OutboundTranslationSlice_Callback.res +40 -2
- package/src/components/OutboundTranslationSlice/OutboundTranslationSlice_Callback.res.mjs +57 -11
- package/src/components/StateChangeSlice/StateChangeSlice_Callback.res +4 -0
- package/src/components/StateChangeSlice/StateChangeSlice_Callback.res.mjs +4 -4
- package/tests/commandtopic/CommandOutcomeLineTest.res.mjs +3 -3
- package/tests/commandtopic/CommandTopicHelpersRejectionTest.res +102 -0
- package/tests/commandtopic/CommandTopicHelpersRejectionTest.res.mjs +101 -3
- package/tests/plugin/PluginStructureAccessTest.res +6 -1
- package/tests/plugin/PluginStructureAccessTest.res.mjs +1 -1
|
@@ -87,115 +87,122 @@ function Make(RuntimeEnvironment) {
|
|
|
87
87
|
await queryDbOps.save(Id$Reventless.$$String.makeFromString(param[0]), param[1], "Overwrite", undefined);
|
|
88
88
|
});
|
|
89
89
|
};
|
|
90
|
-
let make = (allEventTopics, publishJsons, context, runtime, opts) =>
|
|
91
|
-
let
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}, opts);
|
|
101
|
-
sourceNames.forEach(sourceName => {
|
|
102
|
-
if (sourceName in allEventTopics) {
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
let availableNames = Object.keys(allEventTopics).toSorted(Primitive_string.compare).join(", ");
|
|
106
|
-
Stdlib_JsError.throwWithMessage(`AutomationSlice "` + Spec.name + `" has a Mapping with sourceName "` + sourceName + `", but no EventTopic with that key exists in allEventTopics. ` + (`Available source names: [` + availableNames + `]. `) + `Check Mapping.Make's first arg matches an Aggregate Spec.name or a DCB source name (typically "<pluginName>DcbEventLog").`);
|
|
107
|
-
});
|
|
108
|
-
if (readsClock && Stdlib_Option.isNone(Spec.schedule) && sourceNames.length === 0) {
|
|
109
|
-
Stdlib_JsError.throwWithMessage(`AutomationSlice "` + Spec.name + `" maps the Clock source but declares no schedule and reads no event that could set one, so no tick will ever reach it. Declare \`let schedule\` on its spec.`);
|
|
110
|
-
}
|
|
111
|
-
let schedulesDb = readsClock ? Primitive_option.some(SchedulesQueryDb.make(Api.api(), Api.apiRole(), undefined, {
|
|
112
|
-
kind: "AutomationSlice",
|
|
113
|
-
name: Spec.name
|
|
114
|
-
}, opts)) : undefined;
|
|
115
|
-
let schedulesOps = schedulesDb !== undefined ? Component$ReventlessCore.operations(Primitive_option.valFromOption(schedulesDb)).apply(ops => ops) : Pulumi.output(undefined);
|
|
116
|
-
let platform = Schedules.platformFor(Spec.name);
|
|
117
|
-
let storedSchedules = {
|
|
118
|
-
contents: []
|
|
119
|
-
};
|
|
120
|
-
let sourceSet = Belt_SetString.fromArray(sourceNames);
|
|
121
|
-
let eventTopics = EventTopic$ReventlessCore.filter(allEventTopics, sourceSet);
|
|
122
|
-
let eventCollector = Pulumi.all([
|
|
123
|
-
Component$ReventlessCore.operations(queryDb),
|
|
124
|
-
publishJsons,
|
|
125
|
-
schedulesOps
|
|
126
|
-
]).apply(param => {
|
|
127
|
-
let schedulesOps = param[2];
|
|
128
|
-
let publishJsonsFn = param[1];
|
|
129
|
-
let queryDbOps = param[0];
|
|
130
|
-
let ec = SpecificEventCollector.make(Spec.name, eventTopics, {
|
|
90
|
+
let make = (allEventTopics, publishJsons, publishJsonsAndWaitOpt, context, runtime, opts) => {
|
|
91
|
+
let publishJsonsAndWait = publishJsonsAndWaitOpt !== undefined ? publishJsonsAndWaitOpt : Pulumi.output(undefined);
|
|
92
|
+
return Component$ReventlessCore.make(ComponentType$ReventlessCore.toString(AutomationSlice$ReventlessCore.componentType), Spec.name, (extra, extra$1) => {
|
|
93
|
+
let opts_parent = Component$ReventlessCore.toPulumiResource(extra);
|
|
94
|
+
let opts = {
|
|
95
|
+
parent: opts_parent
|
|
96
|
+
};
|
|
97
|
+
let memorySize = RuntimeHints$ReventlessInfra.resolveMemory(runtime, 1024);
|
|
98
|
+
let timeout = RuntimeHints$ReventlessInfra.resolveTimeout(runtime, 30);
|
|
99
|
+
let queryDb = SpecificQueryDb.make(Api.api(), Api.apiRole(), undefined, {
|
|
131
100
|
kind: "AutomationSlice",
|
|
132
101
|
name: Spec.name
|
|
133
102
|
}, opts);
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
let changes = Callback.takeScheduleChanges();
|
|
138
|
-
if (changes.length !== 0) {
|
|
139
|
-
await syncSchedules(schedulesOps, storedSchedules);
|
|
140
|
-
await AutomationSlice_Schedules$ReventlessCore.tell(platform, changes);
|
|
141
|
-
}
|
|
142
|
-
Stdlib_Promise.$$catch(Callback.phase2(publishJsonsFn).then(() => syncToQueryDb(queryDbOps)), exn => {
|
|
143
|
-
let errMsg = Stdlib_Option.getOr(Stdlib_Option.flatMap(Stdlib_JsExn.fromException(exn), Stdlib_JsExn.message), "unknown");
|
|
144
|
-
Effect.runSync(EffectLogger$ReventlessCore.logError(`AutomationSlice(` + Spec.name + `)`, undefined, undefined, `detached phase 2 error: ` + errMsg));
|
|
145
|
-
return Promise.resolve();
|
|
146
|
-
});
|
|
147
|
-
}));
|
|
148
|
-
let handler = SpecificEventCollector.makeHandler(ec, jsonEventsHandler);
|
|
149
|
-
let resources = Component$ReventlessCore.outputs(queryDb).resources;
|
|
150
|
-
EventCollectorRuntimeBuilder.forEventCollector(handler, eventTopics, resources, memorySize, timeout, ec);
|
|
151
|
-
return ec;
|
|
152
|
-
});
|
|
153
|
-
Component$ReventlessCore.setOperations(extra, Pulumi.all([
|
|
154
|
-
Output$Pulumi.flatMap(eventCollector, Component$ReventlessCore.operations),
|
|
155
|
-
publishJsons,
|
|
156
|
-
Component$ReventlessCore.operations(queryDb),
|
|
157
|
-
schedulesOps
|
|
158
|
-
]).apply(param => {
|
|
159
|
-
let schedulesOps = param[3];
|
|
160
|
-
let queryDbOps = param[2];
|
|
161
|
-
let publishJsonsFn = param[1];
|
|
162
|
-
let processPending = async () => {
|
|
163
|
-
await Callback.phase2(publishJsonsFn);
|
|
164
|
-
return await syncToQueryDb(queryDbOps);
|
|
165
|
-
};
|
|
166
|
-
let reconcileSchedules = async () => {
|
|
167
|
-
if (readsClock) {
|
|
168
|
-
await AutomationSlice_Schedules$ReventlessCore.reconcile(Callback.schedules, platform, Spec.schedule, Date.now());
|
|
169
|
-
return await syncSchedules(schedulesOps, storedSchedules);
|
|
103
|
+
sourceNames.forEach(sourceName => {
|
|
104
|
+
if (sourceName in allEventTopics) {
|
|
105
|
+
return;
|
|
170
106
|
}
|
|
107
|
+
let availableNames = Object.keys(allEventTopics).toSorted(Primitive_string.compare).join(", ");
|
|
108
|
+
Stdlib_JsError.throwWithMessage(`AutomationSlice "` + Spec.name + `" has a Mapping with sourceName "` + sourceName + `", but no EventTopic with that key exists in allEventTopics. ` + (`Available source names: [` + availableNames + `]. `) + `Check Mapping.Make's first arg matches an Aggregate Spec.name or a DCB source name (typically "<pluginName>DcbEventLog").`);
|
|
109
|
+
});
|
|
110
|
+
if (readsClock && Stdlib_Option.isNone(Spec.schedule) && sourceNames.length === 0) {
|
|
111
|
+
Stdlib_JsError.throwWithMessage(`AutomationSlice "` + Spec.name + `" maps the Clock source but declares no schedule and reads no event that could set one, so no tick will ever reach it. Declare \`let schedule\` on its spec.`);
|
|
112
|
+
}
|
|
113
|
+
let schedulesDb = readsClock ? Primitive_option.some(SchedulesQueryDb.make(Api.api(), Api.apiRole(), undefined, {
|
|
114
|
+
kind: "AutomationSlice",
|
|
115
|
+
name: Spec.name
|
|
116
|
+
}, opts)) : undefined;
|
|
117
|
+
let schedulesOps = schedulesDb !== undefined ? Component$ReventlessCore.operations(Primitive_option.valFromOption(schedulesDb)).apply(ops => ops) : Pulumi.output(undefined);
|
|
118
|
+
let platform = Schedules.platformFor(Spec.name);
|
|
119
|
+
let storedSchedules = {
|
|
120
|
+
contents: []
|
|
171
121
|
};
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
122
|
+
let sourceSet = Belt_SetString.fromArray(sourceNames);
|
|
123
|
+
let eventTopics = EventTopic$ReventlessCore.filter(allEventTopics, sourceSet);
|
|
124
|
+
let eventCollector = Pulumi.all([
|
|
125
|
+
Component$ReventlessCore.operations(queryDb),
|
|
126
|
+
publishJsons,
|
|
127
|
+
schedulesOps,
|
|
128
|
+
publishJsonsAndWait
|
|
129
|
+
]).apply(param => {
|
|
130
|
+
let publishJsonsAndWait = param[3];
|
|
131
|
+
let schedulesOps = param[2];
|
|
132
|
+
let publishJsonsFn = param[1];
|
|
133
|
+
let queryDbOps = param[0];
|
|
134
|
+
let ec = SpecificEventCollector.make(Spec.name, eventTopics, {
|
|
135
|
+
kind: "AutomationSlice",
|
|
136
|
+
name: Spec.name
|
|
137
|
+
}, opts);
|
|
138
|
+
let jsonEventsHandler = stream => Effect$1.flatMap(Stream.runCollect(stream), jsons => Effect$1.promise(async () => {
|
|
139
|
+
await Callback.phase1(jsons, context, Capabilities.capabilities());
|
|
177
140
|
await syncToQueryDb(queryDbOps);
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
141
|
+
let changes = Callback.takeScheduleChanges();
|
|
142
|
+
if (changes.length !== 0) {
|
|
143
|
+
await syncSchedules(schedulesOps, storedSchedules);
|
|
144
|
+
await AutomationSlice_Schedules$ReventlessCore.tell(platform, changes);
|
|
145
|
+
}
|
|
146
|
+
Stdlib_Promise.$$catch(Callback.phase2(publishJsonsFn, publishJsonsAndWait).then(() => syncToQueryDb(queryDbOps)), exn => {
|
|
147
|
+
let errMsg = Stdlib_Option.getOr(Stdlib_Option.flatMap(Stdlib_JsExn.fromException(exn), Stdlib_JsExn.message), "unknown");
|
|
148
|
+
Effect.runSync(EffectLogger$ReventlessCore.logError(`AutomationSlice(` + Spec.name + `)`, undefined, undefined, `detached phase 2 error: ` + errMsg));
|
|
149
|
+
return Promise.resolve();
|
|
150
|
+
});
|
|
151
|
+
}));
|
|
152
|
+
let handler = SpecificEventCollector.makeHandler(ec, jsonEventsHandler);
|
|
153
|
+
let resources = Component$ReventlessCore.outputs(queryDb).resources;
|
|
154
|
+
EventCollectorRuntimeBuilder.forEventCollector(handler, eventTopics, resources, memorySize, timeout, ec);
|
|
155
|
+
return ec;
|
|
156
|
+
});
|
|
157
|
+
Component$ReventlessCore.setOperations(extra, Pulumi.all([
|
|
158
|
+
Output$Pulumi.flatMap(eventCollector, Component$ReventlessCore.operations),
|
|
159
|
+
publishJsons,
|
|
160
|
+
Component$ReventlessCore.operations(queryDb),
|
|
161
|
+
schedulesOps,
|
|
162
|
+
publishJsonsAndWait
|
|
163
|
+
]).apply(param => {
|
|
164
|
+
let publishJsonsAndWait = param[4];
|
|
165
|
+
let schedulesOps = param[3];
|
|
166
|
+
let queryDbOps = param[2];
|
|
167
|
+
let publishJsonsFn = param[1];
|
|
168
|
+
let processPending = async () => {
|
|
169
|
+
await Callback.phase2(publishJsonsFn, publishJsonsAndWait);
|
|
170
|
+
return await syncToQueryDb(queryDbOps);
|
|
171
|
+
};
|
|
172
|
+
let reconcileSchedules = async () => {
|
|
173
|
+
if (readsClock) {
|
|
174
|
+
await AutomationSlice_Schedules$ReventlessCore.reconcile(Callback.schedules, platform, Spec.schedule, Date.now());
|
|
175
|
+
return await syncSchedules(schedulesOps, storedSchedules);
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
return {
|
|
179
|
+
enqueueEvent: param[0].enqueueEvent,
|
|
180
|
+
processPending: processPending,
|
|
181
|
+
tick: async (key, at) => {
|
|
182
|
+
await Callback.phase1([AutomationSlice_Callback$ReventlessCore.tickEvent(key, at)], context, Capabilities.capabilities());
|
|
183
|
+
await syncToQueryDb(queryDbOps);
|
|
184
|
+
await syncSchedules(schedulesOps, storedSchedules);
|
|
185
|
+
await AutomationSlice_Schedules$ReventlessCore.tell(platform, Callback.takeScheduleChanges());
|
|
186
|
+
return await processPending();
|
|
187
|
+
},
|
|
188
|
+
reconcileSchedules: reconcileSchedules,
|
|
189
|
+
rebuildSchedules: async events => {
|
|
190
|
+
Callback.rebuildSchedules(events);
|
|
191
|
+
return await reconcileSchedules();
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
}));
|
|
195
|
+
let aggregatedResources = Object.values(eventTopics).flatMap(t => t.resources);
|
|
196
|
+
let outputs_queryDb = Component$ReventlessCore.outputs(queryDb);
|
|
197
|
+
let outputs_schedulesDb = Stdlib_Option.map(schedulesDb, Component$ReventlessCore.outputs);
|
|
198
|
+
let outputs = {
|
|
199
|
+
resources: aggregatedResources,
|
|
200
|
+
queryDb: outputs_queryDb,
|
|
201
|
+
schedulesDb: outputs_schedulesDb
|
|
187
202
|
};
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
let outputs_schedulesDb = Stdlib_Option.map(schedulesDb, Component$ReventlessCore.outputs);
|
|
192
|
-
let outputs = {
|
|
193
|
-
resources: aggregatedResources,
|
|
194
|
-
queryDb: outputs_queryDb,
|
|
195
|
-
schedulesDb: outputs_schedulesDb
|
|
196
|
-
};
|
|
197
|
-
return Component$ReventlessCore.setOutputs(extra, outputs);
|
|
198
|
-
}, opts);
|
|
203
|
+
return Component$ReventlessCore.setOutputs(extra, outputs);
|
|
204
|
+
}, opts);
|
|
205
|
+
};
|
|
199
206
|
return {
|
|
200
207
|
Spec: Spec,
|
|
201
208
|
Automation: Automation,
|
|
@@ -38,6 +38,8 @@ type todoRow = {
|
|
|
38
38
|
rehydrated through `S.parseOrThrow`, and a required field would fail that
|
|
39
39
|
decode — silently, since the restore swallows it per row. */
|
|
40
40
|
maxRetries?: int,
|
|
41
|
+
/** Why the last attempt failed: the target's refusal, or the failure to send. */
|
|
42
|
+
lastError?: string,
|
|
41
43
|
/** The event that created the row, so the commands sent for it continue its
|
|
42
44
|
flow. Absent on rows written before it existed, and on rows a tick created. */
|
|
43
45
|
source?: Message.flowSource,
|
|
@@ -72,6 +74,7 @@ let todoRowSchemaFor = (itemSchema: S.t<'item>): S.t<todoRow> =>
|
|
|
72
74
|
completedAt: ?s.matches(S.option(S.string)),
|
|
73
75
|
retryCount: s.matches(S.int),
|
|
74
76
|
maxRetries: ?s.matches(S.option(S.int)),
|
|
77
|
+
lastError: ?s.matches(S.option(S.string)),
|
|
75
78
|
source: ?s.matches(S.option(Message.flowSourceSchema)),
|
|
76
79
|
})
|
|
77
80
|
|
|
@@ -92,8 +95,15 @@ type phase1 = (
|
|
|
92
95
|
~capabilities: Reventless.Capabilities.t,
|
|
93
96
|
) => promise<unit>
|
|
94
97
|
|
|
95
|
-
/** Phase 2: process all pending items, publishing commands.
|
|
96
|
-
|
|
98
|
+
/** Phase 2: process all pending items, publishing commands.
|
|
99
|
+
|
|
100
|
+
With `~publishJsonsAndWait`, each command's outcome is read where the target
|
|
101
|
+
answers inline: a refusal is recorded on the row instead of waiting out the
|
|
102
|
+
processing timeout. An outcome of `Pending` leaves the row to that timeout. */
|
|
103
|
+
type phase2 = (
|
|
104
|
+
ReventlessInfra.CommandTopic.publishJsons,
|
|
105
|
+
~publishJsonsAndWait: CommandTopic_Helpers.publishJsonsAndWait=?,
|
|
106
|
+
) => promise<unit>
|
|
97
107
|
|
|
98
108
|
/** The whole protocol as a value, for a driver that holds a built callback and
|
|
99
109
|
knows nothing of the Spec behind it. */
|
|
@@ -289,11 +299,33 @@ module Make = (
|
|
|
289
299
|
budget runs out rather than being left to fall out of the next pass's
|
|
290
300
|
filter, so a reader never has to compare `retryCount` against a constant
|
|
291
301
|
that lives only in this Spec. */
|
|
292
|
-
let afterFailedAttempt = (row: todoRow): todoRow => {
|
|
302
|
+
let afterFailedAttempt = (row: todoRow, ~lastError: option<string>=?): todoRow => {
|
|
293
303
|
let retryCount = row.retryCount + 1
|
|
294
|
-
{
|
|
304
|
+
{
|
|
305
|
+
...row,
|
|
306
|
+
status: retryCount >= Spec.maxRetries ? Abandoned : Failed,
|
|
307
|
+
retryCount,
|
|
308
|
+
lastError: ?switch lastError {
|
|
309
|
+
| Some(_) as given => given
|
|
310
|
+
| None => row.lastError
|
|
311
|
+
},
|
|
312
|
+
}
|
|
295
313
|
}
|
|
296
314
|
|
|
315
|
+
/** The row after the target refused its command. A business refusal or an
|
|
316
|
+
infrastructure failure is a failed attempt, retried on the next pass: the
|
|
317
|
+
target may not yet have seen an event the command depends on. A permission
|
|
318
|
+
refusal ends the row, since waiting cannot change it. */
|
|
319
|
+
let afterRefusal = (
|
|
320
|
+
row: todoRow,
|
|
321
|
+
~cause: CommandTopic_Helpers.refusalCause,
|
|
322
|
+
~lastError: string,
|
|
323
|
+
): todoRow =>
|
|
324
|
+
switch cause {
|
|
325
|
+
| AccessRefusal => {...row->afterFailedAttempt(~lastError), status: Abandoned}
|
|
326
|
+
| DomainRejection | InfrastructureFailure => row->afterFailedAttempt(~lastError)
|
|
327
|
+
}
|
|
328
|
+
|
|
297
329
|
/** The command a slice wants published now that this item will never be
|
|
298
330
|
processed again, if it wants one. The row is `Abandoned` either way. */
|
|
299
331
|
let abandonmentCommand = async (~id: string, ~row: todoRow): option<
|
|
@@ -301,7 +333,10 @@ module Make = (
|
|
|
301
333
|
> =>
|
|
302
334
|
switch await openRow(~id, row) {
|
|
303
335
|
| Open({key, item}) =>
|
|
304
|
-
Automation.onExhausted(key, item)->Option.flatMap(((
|
|
336
|
+
Automation.onExhausted(key, item, ~lastError=row.lastError)->Option.flatMap(((
|
|
337
|
+
targetId,
|
|
338
|
+
command,
|
|
339
|
+
)) =>
|
|
305
340
|
switch command->Reventless.Util_Sury.toJson(Spec.commandSchema) {
|
|
306
341
|
| commandJson => Some({Reventless.Message.id: targetId, meta: makeMeta(row), commandJson})
|
|
307
342
|
| exception _ =>
|
|
@@ -461,8 +496,17 @@ module Make = (
|
|
|
461
496
|
scheduleChanges := []
|
|
462
497
|
}
|
|
463
498
|
|
|
464
|
-
let phase2 = async (
|
|
499
|
+
let phase2 = async (
|
|
500
|
+
publishJsons: ReventlessInfra.CommandTopic.publishJsons,
|
|
501
|
+
~publishJsonsAndWait: option<CommandTopic_Helpers.publishJsonsAndWait>=?,
|
|
502
|
+
) => {
|
|
465
503
|
let publishJsons = CommandSent.announcing(~comp=`AutomationSlice(${Spec.name})`, publishJsons)
|
|
504
|
+
let publishJsonsAndWait =
|
|
505
|
+
publishJsonsAndWait->Option.map(wait =>
|
|
506
|
+
CommandSent.announcingAndWaiting(~comp=`AutomationSlice(${Spec.name})`, wait)
|
|
507
|
+
)
|
|
508
|
+
// The row each sent command belongs to, by the command's message id.
|
|
509
|
+
let rowOfMsgId: dict<string> = Dict.make()
|
|
466
510
|
let currentTime = await Clock.currentTimeMillis->Effect.runPromise
|
|
467
511
|
// A `Failed` row at or past the ceiling is one an older build left stranded,
|
|
468
512
|
// or one whose Spec lowered `maxRetries` under it. Either way it is abandoned
|
|
@@ -547,15 +591,38 @@ module Make = (
|
|
|
547
591
|
meta: makeMeta(row),
|
|
548
592
|
commandJson,
|
|
549
593
|
}
|
|
550
|
-
|
|
594
|
+
rowOfMsgId->Dict.set(msg.meta.msgId, id)
|
|
595
|
+
commands->Array.push(msg)
|
|
551
596
|
})
|
|
552
597
|
| None => () // Skip — process returned None
|
|
553
598
|
}
|
|
554
599
|
}
|
|
555
600
|
}
|
|
556
601
|
|
|
602
|
+
// A row `resolve` already completed while the target ran is left as it is.
|
|
603
|
+
let recordOutcome = (outcome: CommandTopic_Helpers.commandOutcome) =>
|
|
604
|
+
switch outcome {
|
|
605
|
+
| Rejected({msgId, errorCode, errorDetail, cause}) =>
|
|
606
|
+
switch rowOfMsgId
|
|
607
|
+
->Dict.get(msgId)
|
|
608
|
+
->Option.flatMap(id => todoItems->Dict.get(id)->Option.map(row => (id, row))) {
|
|
609
|
+
| Some((id, row)) if row.status == Processing =>
|
|
610
|
+
let lastError = CommandTopic_Helpers.describeRefusal(~errorCode, ~errorDetail)
|
|
611
|
+
let updated = row->afterRefusal(~cause, ~lastError)
|
|
612
|
+
todoItems->Dict.set(id, updated)
|
|
613
|
+
if updated.status == Abandoned {
|
|
614
|
+
newlyAbandoned->Array.push(id)
|
|
615
|
+
}
|
|
616
|
+
| _ => ()
|
|
617
|
+
}
|
|
618
|
+
| Accepted(_) | Pending(_) => ()
|
|
619
|
+
}
|
|
620
|
+
|
|
557
621
|
if commands->Array.length > 0 {
|
|
558
|
-
try
|
|
622
|
+
try switch publishJsonsAndWait {
|
|
623
|
+
| Some(wait) => (await wait(commands))->Array.forEach(recordOutcome)
|
|
624
|
+
| None => await publishJsons(commands)
|
|
625
|
+
} catch {
|
|
559
626
|
| exn =>
|
|
560
627
|
let errMsg =
|
|
561
628
|
exn->JsExn.fromException->Option.flatMap(JsExn.message)->Option.getOr("unknown")
|
|
@@ -17,6 +17,7 @@ import * as Util_Sury$Reventless from "@reventlessdev/reventless-spec/src/util/U
|
|
|
17
17
|
import * as Message$ReventlessCore from "../../Message.res.mjs";
|
|
18
18
|
import * as CommandSent$ReventlessCore from "../../CommandSent.res.mjs";
|
|
19
19
|
import * as EffectLogger$ReventlessCore from "../../util/EffectLogger.res.mjs";
|
|
20
|
+
import * as CommandTopic_Helpers$ReventlessCore from "../CommandTopic/CommandTopic_Helpers.res.mjs";
|
|
20
21
|
import * as AutomationSlice_Route$ReventlessCore from "./AutomationSlice_Route.res.mjs";
|
|
21
22
|
import * as AutomationSlice_Schedules$ReventlessCore from "./AutomationSlice_Schedules.res.mjs";
|
|
22
23
|
|
|
@@ -36,6 +37,7 @@ let todoRowSchema = Sury.$schema(s => ({
|
|
|
36
37
|
completedAt: s.m(Sury.$option(Sury.string)),
|
|
37
38
|
retryCount: s.m(Sury.int32),
|
|
38
39
|
maxRetries: s.m(Sury.$option(Sury.int32)),
|
|
40
|
+
lastError: s.m(Sury.$option(Sury.string)),
|
|
39
41
|
source: s.m(Sury.$option(Message$ReventlessCore.flowSourceSchema))
|
|
40
42
|
}));
|
|
41
43
|
|
|
@@ -48,6 +50,7 @@ function todoRowSchemaFor(itemSchema) {
|
|
|
48
50
|
completedAt: s.m(Sury.$option(Sury.string)),
|
|
49
51
|
retryCount: s.m(Sury.int32),
|
|
50
52
|
maxRetries: s.m(Sury.$option(Sury.int32)),
|
|
53
|
+
lastError: s.m(Sury.$option(Sury.string)),
|
|
51
54
|
source: s.m(Sury.$option(Message$ReventlessCore.flowSourceSchema))
|
|
52
55
|
}));
|
|
53
56
|
}
|
|
@@ -188,18 +191,30 @@ function Make(Spec) {
|
|
|
188
191
|
return decode(data$1, key);
|
|
189
192
|
};
|
|
190
193
|
let processingTimeoutMs = 15 * 60 * 1000;
|
|
191
|
-
let afterFailedAttempt = row => {
|
|
194
|
+
let afterFailedAttempt = (row, lastError) => {
|
|
192
195
|
let retryCount = row.retryCount + 1 | 0;
|
|
193
196
|
let newrecord = {...row};
|
|
197
|
+
newrecord.lastError = lastError !== undefined ? lastError : row.lastError;
|
|
194
198
|
newrecord.retryCount = retryCount;
|
|
195
199
|
newrecord.status = retryCount >= Spec.maxRetries ? "Abandoned" : "Failed";
|
|
196
200
|
return newrecord;
|
|
197
201
|
};
|
|
202
|
+
let afterRefusal = (row, cause, lastError) => {
|
|
203
|
+
switch (cause) {
|
|
204
|
+
case "DomainRejection" :
|
|
205
|
+
case "InfrastructureFailure" :
|
|
206
|
+
return afterFailedAttempt(row, lastError);
|
|
207
|
+
case "AccessRefusal" :
|
|
208
|
+
let newrecord = {...afterFailedAttempt(row, lastError)};
|
|
209
|
+
newrecord.status = "Abandoned";
|
|
210
|
+
return newrecord;
|
|
211
|
+
}
|
|
212
|
+
};
|
|
198
213
|
let abandonmentCommand = async (id, row) => {
|
|
199
214
|
let match = await openRow(id, row);
|
|
200
215
|
switch (match.TAG) {
|
|
201
216
|
case "Open" :
|
|
202
|
-
return Stdlib_Option.flatMap(Automation.onExhausted(match.key, match.item), param => {
|
|
217
|
+
return Stdlib_Option.flatMap(Automation.onExhausted(match.key, match.item, row.lastError), param => {
|
|
203
218
|
let commandJson;
|
|
204
219
|
try {
|
|
205
220
|
commandJson = Util_Sury$Reventless.toJson(param[1], Spec.commandSchema);
|
|
@@ -326,8 +341,10 @@ function Make(Spec) {
|
|
|
326
341
|
});
|
|
327
342
|
scheduleChanges.contents = [];
|
|
328
343
|
};
|
|
329
|
-
let phase2 = async publishJsons => {
|
|
344
|
+
let phase2 = async (publishJsons, publishJsonsAndWait) => {
|
|
330
345
|
let publishJsons$1 = CommandSent$ReventlessCore.announcing(`AutomationSlice(` + Spec.name + `)`, publishJsons);
|
|
346
|
+
let publishJsonsAndWait$1 = Stdlib_Option.map(publishJsonsAndWait, wait => CommandSent$ReventlessCore.announcingAndWaiting(`AutomationSlice(` + Spec.name + `)`, wait));
|
|
347
|
+
let rowOfMsgId = {};
|
|
331
348
|
let currentTime = await Effect.runPromise(Clock.currentTimeMillis);
|
|
332
349
|
let newlyAbandoned = [];
|
|
333
350
|
Object.entries(todoItems).forEach(param => {
|
|
@@ -344,7 +361,7 @@ function Make(Spec) {
|
|
|
344
361
|
if (currentTime - match$1 < processingTimeoutMs) {
|
|
345
362
|
return;
|
|
346
363
|
}
|
|
347
|
-
let updated = afterFailedAttempt(row);
|
|
364
|
+
let updated = afterFailedAttempt(row, undefined);
|
|
348
365
|
todoItems[id] = updated;
|
|
349
366
|
if (updated.status === "Abandoned") {
|
|
350
367
|
newlyAbandoned.push(id);
|
|
@@ -394,7 +411,7 @@ function Make(Spec) {
|
|
|
394
411
|
let exn = Primitive_exceptions.internalToException(raw_exn);
|
|
395
412
|
let errMsg = Stdlib_Option.getOr(Stdlib_Option.flatMap(Stdlib_JsExn.fromException(exn), Stdlib_JsExn.message), "unknown");
|
|
396
413
|
Effect.runSync(EffectLogger$ReventlessCore.logError(`AutomationSlice(` + Spec.name + `)`, undefined, Stdlib_Option.map(row.source, EffectLogger$ReventlessCore.idsOfSource), `failed to encode command: ` + errMsg));
|
|
397
|
-
let updated = afterFailedAttempt(row);
|
|
414
|
+
let updated = afterFailedAttempt(row, undefined);
|
|
398
415
|
todoItems[id] = updated;
|
|
399
416
|
if (updated.status === "Abandoned") {
|
|
400
417
|
newlyAbandoned.push(id);
|
|
@@ -408,6 +425,7 @@ function Make(Spec) {
|
|
|
408
425
|
meta: msg_meta,
|
|
409
426
|
commandJson: commandJson
|
|
410
427
|
};
|
|
428
|
+
rowOfMsgId[msg_meta.msgId] = id;
|
|
411
429
|
commands.push(msg);
|
|
412
430
|
});
|
|
413
431
|
}
|
|
@@ -424,9 +442,42 @@ function Make(Spec) {
|
|
|
424
442
|
break;
|
|
425
443
|
}
|
|
426
444
|
}
|
|
445
|
+
let recordOutcome = outcome => {
|
|
446
|
+
switch (outcome.TAG) {
|
|
447
|
+
case "Rejected" :
|
|
448
|
+
let match = Stdlib_Option.flatMap(rowOfMsgId[outcome.msgId], id => Stdlib_Option.map(todoItems[id], row => [
|
|
449
|
+
id,
|
|
450
|
+
row
|
|
451
|
+
]));
|
|
452
|
+
if (match === undefined) {
|
|
453
|
+
return;
|
|
454
|
+
}
|
|
455
|
+
let row = match[1];
|
|
456
|
+
if (row.status !== "Processing") {
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
459
|
+
let id = match[0];
|
|
460
|
+
let lastError = CommandTopic_Helpers$ReventlessCore.describeRefusal(outcome.errorCode, outcome.errorDetail);
|
|
461
|
+
let updated = afterRefusal(row, outcome.cause, lastError);
|
|
462
|
+
todoItems[id] = updated;
|
|
463
|
+
if (updated.status === "Abandoned") {
|
|
464
|
+
newlyAbandoned.push(id);
|
|
465
|
+
return;
|
|
466
|
+
} else {
|
|
467
|
+
return;
|
|
468
|
+
}
|
|
469
|
+
case "Accepted" :
|
|
470
|
+
case "Pending" :
|
|
471
|
+
return;
|
|
472
|
+
}
|
|
473
|
+
};
|
|
427
474
|
if (commands.length !== 0) {
|
|
428
475
|
try {
|
|
429
|
-
|
|
476
|
+
if (publishJsonsAndWait$1 !== undefined) {
|
|
477
|
+
(await publishJsonsAndWait$1(commands)).forEach(recordOutcome);
|
|
478
|
+
} else {
|
|
479
|
+
await publishJsons$1(commands);
|
|
480
|
+
}
|
|
430
481
|
} catch (raw_exn$1) {
|
|
431
482
|
let exn$1 = Primitive_exceptions.internalToException(raw_exn$1);
|
|
432
483
|
let errMsg$1 = Stdlib_Option.getOr(Stdlib_Option.flatMap(Stdlib_JsExn.fromException(exn$1), Stdlib_JsExn.message), "unknown");
|
|
@@ -440,7 +491,7 @@ function Make(Spec) {
|
|
|
440
491
|
if (current.status !== "Processing") {
|
|
441
492
|
return;
|
|
442
493
|
}
|
|
443
|
-
let updated = afterFailedAttempt(param[1]);
|
|
494
|
+
let updated = afterFailedAttempt(param[1], undefined);
|
|
444
495
|
todoItems[id] = updated;
|
|
445
496
|
if (updated.status === "Abandoned") {
|
|
446
497
|
newlyAbandoned.push(id);
|
|
@@ -66,7 +66,7 @@ function makeGenerateCommand(publishJsons, publishJsonsAndWait, serviceName, com
|
|
|
66
66
|
let refusedBeforeHandler = (meta, reason, access) => {
|
|
67
67
|
Effect.runSync(EffectLogger$ReventlessCore.logWarn(`CommandGenerator(` + serviceName + `)`, undefined, EffectLogger$ReventlessCore.idsOf(undefined, undefined, meta), `refused before its handler: ` + reason));
|
|
68
68
|
if (access) {
|
|
69
|
-
return CommandTopic_Helpers$ReventlessCore.fireCommandOutcome(serviceName, meta.msgId, meta.correlationId, undefined, {
|
|
69
|
+
return CommandTopic_Helpers$ReventlessCore.fireCommandOutcome(serviceName, meta.msgId, meta.correlationId, undefined, undefined, {
|
|
70
70
|
TAG: "OutcomeRejected",
|
|
71
71
|
errorCode: CommandOutcome$Reventless.code("Forbidden"),
|
|
72
72
|
errorDetail: reason,
|
|
@@ -43,6 +43,8 @@ let acceptedResultChannel = CommandTopic_Helpers$ReventlessCore.acceptedResultCh
|
|
|
43
43
|
|
|
44
44
|
let rejectedResultChannel = CommandTopic_Helpers$ReventlessCore.rejectedResultChannel;
|
|
45
45
|
|
|
46
|
+
let inlineWaiters = CommandTopic_Helpers$ReventlessCore.inlineWaiters;
|
|
47
|
+
|
|
46
48
|
let ownershipRefusal = CommandTopic_Helpers$ReventlessCore.ownershipRefusal;
|
|
47
49
|
|
|
48
50
|
let reportAccepted = CommandTopic_Helpers$ReventlessCore.reportAccepted;
|
|
@@ -51,6 +53,10 @@ let reportRejected = CommandTopic_Helpers$ReventlessCore.reportRejected;
|
|
|
51
53
|
|
|
52
54
|
let commandOutcomeToJson = CommandTopic_Helpers$ReventlessCore.commandOutcomeToJson;
|
|
53
55
|
|
|
56
|
+
let commandOutcomeOfJson = CommandTopic_Helpers$ReventlessCore.commandOutcomeOfJson;
|
|
57
|
+
|
|
58
|
+
let describeRefusal = CommandTopic_Helpers$ReventlessCore.describeRefusal;
|
|
59
|
+
|
|
54
60
|
let encodeCommandJson = CommandTopic_Helpers$ReventlessCore.encodeCommandJson;
|
|
55
61
|
|
|
56
62
|
let runInlineAndCollect = CommandTopic_Helpers$ReventlessCore.runInlineAndCollect;
|
|
@@ -78,10 +84,13 @@ export {
|
|
|
78
84
|
fireCommandOutcome,
|
|
79
85
|
acceptedResultChannel,
|
|
80
86
|
rejectedResultChannel,
|
|
87
|
+
inlineWaiters,
|
|
81
88
|
ownershipRefusal,
|
|
82
89
|
reportAccepted,
|
|
83
90
|
reportRejected,
|
|
84
91
|
commandOutcomeToJson,
|
|
92
|
+
commandOutcomeOfJson,
|
|
93
|
+
describeRefusal,
|
|
85
94
|
encodeCommandJson,
|
|
86
95
|
runInlineAndCollect,
|
|
87
96
|
callHandlerWithArray,
|