@reventlessdev/reventless-core 3.0.0-alpha.326 → 3.0.0-alpha.328
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 +18 -0
- package/package.json +6 -6
- package/src/CommandSent.res +22 -0
- package/src/CommandSent.res.mjs +22 -0
- package/src/Projection.res +26 -1
- package/src/Projection.res.mjs +19 -1
- package/src/RowChange.res +37 -0
- package/src/RowChange.res.mjs +62 -0
- package/src/adapter/Runtime/AggregateRuntime_Builder_Common.res.mjs +5 -5
- package/src/adapter/Runtime/EventCollectorRuntime_Builder_Single.res.mjs +2 -2
- package/src/admin/Platform_Admin_Callback.res.mjs +1 -1
- package/src/components/Aggregate/Aggregate_Callback.res +88 -18
- package/src/components/Aggregate/Aggregate_Callback.res.mjs +53 -32
- package/src/components/Api/GraphQL_FragmentGenerator.res +22 -0
- package/src/components/Api/GraphQL_FragmentGenerator.res.mjs +20 -4
- package/src/components/Api/GraphQL_SchemaInspector.res.mjs +2 -2
- package/src/components/AutomationSlice/AutomationSlice_Builder.res.mjs +1 -1
- package/src/components/AutomationSlice/AutomationSlice_Callback.res +9 -0
- package/src/components/AutomationSlice/AutomationSlice_Callback.res.mjs +20 -14
- package/src/components/CommandGenerator/CommandGenerator_Callback.res +47 -6
- package/src/components/CommandGenerator/CommandGenerator_Callback.res.mjs +41 -4
- package/src/components/CommandTopic/CommandTopic_Callback.res.mjs +1 -1
- package/src/components/CommandTopic/CommandTopic_Helpers.res +9 -1
- package/src/components/CommandTopic/CommandTopic_Helpers.res.mjs +7 -6
- package/src/components/CommandTopic/CommandTopic_Operations.res +2 -0
- package/src/components/CommandTopic/CommandTopic_Operations.res.mjs +2 -2
- package/src/components/Counter/Counter_Callback.res.mjs +3 -3
- package/src/components/Counter/Counter_Operations.res.mjs +4 -4
- package/src/components/DcbEventLog/DcbEventLog_Operations.res.mjs +3 -3
- package/src/components/EventLog/EventLog_Operations.res +1 -0
- package/src/components/EventLog/EventLog_Operations.res.mjs +3 -3
- package/src/components/EventMapper/EventMapper_Callback.res +12 -2
- package/src/components/EventMapper/EventMapper_Callback.res.mjs +16 -14
- package/src/components/EventTopic/EventTopic_Operations.res +2 -0
- package/src/components/EventTopic/EventTopic_Operations.res.mjs +2 -2
- package/src/components/Extension/Extension_Operations.res +4 -0
- package/src/components/Extension/Extension_Operations.res.mjs +8 -8
- package/src/components/ExtensionPoint/ExtensionPoint_Callback.res +5 -1
- package/src/components/ExtensionPoint/ExtensionPoint_Callback.res.mjs +4 -3
- package/src/components/ExtensionPoint/ExtensionPoint_Operations.res +2 -0
- package/src/components/ExtensionPoint/ExtensionPoint_Operations.res.mjs +9 -8
- package/src/components/InboundTranslationSlice/InboundTranslationSlice_Callback.res +4 -0
- package/src/components/InboundTranslationSlice/InboundTranslationSlice_Callback.res.mjs +4 -2
- package/src/components/InboundTranslationSlice/InboundTranslationSlice_Webhook.res.mjs +1 -1
- package/src/components/OutboundTranslationSlice/OutboundTranslationSlice_Builder.res.mjs +1 -1
- package/src/components/OutboundTranslationSlice/OutboundTranslationSlice_Callback.res +12 -0
- package/src/components/OutboundTranslationSlice/OutboundTranslationSlice_Callback.res.mjs +14 -12
- package/src/components/QueryDb/QueryDb_Operations.res +2 -0
- package/src/components/QueryDb/QueryDb_Operations.res.mjs +3 -0
- package/src/components/ReadModel/ReadModel_Callback.res +1 -0
- package/src/components/ReadModel/ReadModel_Callback.res.mjs +1 -1
- package/src/components/SideEffectHandler/SideEffectHandler_Callback.res +2 -0
- package/src/components/SideEffectHandler/SideEffectHandler_Callback.res.mjs +6 -6
- package/src/components/StateChangeSlice/StateChangeSlice_Callback.res +36 -7
- package/src/components/StateChangeSlice/StateChangeSlice_Callback.res.mjs +38 -20
- package/src/components/StateViewSlice/StateViewSlice_Builder.res +2 -0
- package/src/components/StateViewSlice/StateViewSlice_Builder.res.mjs +2 -2
- package/src/components/StateViewSlice/StateViewSlice_Callback.res +6 -0
- package/src/components/StateViewSlice/StateViewSlice_Callback.res.mjs +3 -2
- package/src/components/Task/Task_Builder.res +5 -3
- package/src/components/Task/Task_Builder.res.mjs +2 -1
- package/src/plugin/component/Plugin_Callback.res +6 -2
- package/src/plugin/component/Plugin_Callback.res.mjs +3 -2
- package/src/plugin/connect/PluginExtensionPoint_Plugin.res.mjs +6 -6
- package/src/util/CommandPublisher.res.mjs +9 -9
- package/src/util/EffectLogger.res +85 -17
- package/src/util/EffectLogger.res.mjs +63 -12
- package/src/util/FTPHandler.res.mjs +6 -6
- package/src/util/Metrics.res +151 -16
- package/src/util/Metrics.res.mjs +123 -3
- package/src/util/ScheduleOps.res.mjs +4 -4
- package/src/util/Util_AdapterRuntime.res.mjs +2 -2
- package/src/util/Util_Promise.res.mjs +1 -1
- package/src/util/Util_QueryDbRuntime.res.mjs +1 -1
- package/src/util/Validation.res.mjs +1 -1
- package/tests/api/GraphQL_FragmentGeneratorTest.res.mjs +2 -2
- package/tests/api/IdentitySemanticTest.res.mjs +1 -1
- package/tests/commandgenerator/OwnerStampingTest.res +65 -0
- package/tests/commandgenerator/OwnerStampingTest.res.mjs +62 -0
- package/tests/commandtopic/CommandOutcomeHookTest.res +25 -0
- package/tests/commandtopic/CommandOutcomeHookTest.res.mjs +28 -0
- package/tests/commandtopic/CommandTopicHelpersRejectionTest.res.mjs +4 -4
- package/tests/logger/ComponentLineIdsTest.res +97 -0
- package/tests/logger/ComponentLineIdsTest.res.mjs +118 -0
- package/tests/logger/LogFormatTest.res.mjs +5 -5
- package/tests/logger/LoggerSinkTest.res.mjs +3 -3
- package/tests/querydb/RowChangeTest.res +87 -0
- package/tests/querydb/RowChangeTest.res.mjs +157 -0
- package/tests/util/MetricsTest.res +72 -0
- package/tests/util/MetricsTest.res.mjs +108 -0
|
@@ -25,7 +25,7 @@ function Make(MappingSpec) {
|
|
|
25
25
|
if (mapOutgoingEvent$1 !== undefined) {
|
|
26
26
|
return mapOutgoingEvent$1(eventJson$p, ScheduleOps$ReventlessCore.create(scheduler, queue, resourceNaming), ScheduleOps$ReventlessCore.$$delete(scheduler, queue, resourceNaming), queryEngine);
|
|
27
27
|
} else {
|
|
28
|
-
Effect.runSync(EffectLogger$ReventlessCore.logError(`ExtensionPoint(` + MappingSpec.name + `)`, undefined, "mapOutgoingEvent: shouldn't be called, because Plugin EventCollector shouldn't subscribe to EventLog stream not having mapOutgoingEvent() !"));
|
|
28
|
+
Effect.runSync(EffectLogger$ReventlessCore.logError(`ExtensionPoint(` + MappingSpec.name + `)`, undefined, undefined, "mapOutgoingEvent: shouldn't be called, because Plugin EventCollector shouldn't subscribe to EventLog stream not having mapOutgoingEvent() !"));
|
|
29
29
|
return [];
|
|
30
30
|
}
|
|
31
31
|
};
|
|
@@ -48,7 +48,7 @@ function Make(MappingSpec) {
|
|
|
48
48
|
} catch (raw_err) {
|
|
49
49
|
let err = Primitive_exceptions.internalToException(raw_err);
|
|
50
50
|
let errMsg = Stdlib_Option.getOr(Stdlib_Option.flatMap(Stdlib_JsExn.fromException(err), Stdlib_JsExn.message), "unknown");
|
|
51
|
-
Effect.runSync(EffectLogger$ReventlessCore.logError(`ExtensionPoint(` + MappingSpec.name + `)`, undefined, `beforePublishHook error: ` + errMsg));
|
|
51
|
+
Effect.runSync(EffectLogger$ReventlessCore.logError(`ExtensionPoint(` + MappingSpec.name + `)`, undefined, undefined, `beforePublishHook error: ` + errMsg));
|
|
52
52
|
finalEventJson = eventJson;
|
|
53
53
|
}
|
|
54
54
|
} else {
|
|
@@ -59,7 +59,7 @@ function Make(MappingSpec) {
|
|
|
59
59
|
} catch (raw_err$1) {
|
|
60
60
|
let err$1 = Primitive_exceptions.internalToException(raw_err$1);
|
|
61
61
|
let errMsg$1 = Stdlib_Option.getOr(Stdlib_Option.flatMap(Stdlib_JsExn.fromException(err$1), Stdlib_JsExn.message), "unknown");
|
|
62
|
-
Effect.runSync(EffectLogger$ReventlessCore.logError(`ExtensionPoint(` + MappingSpec.name + `)`, undefined, `Error on publishToEventTopic command: ` + errMsg$1));
|
|
62
|
+
Effect.runSync(EffectLogger$ReventlessCore.logError(`ExtensionPoint(` + MappingSpec.name + `)`, undefined, undefined, `Error on publishToEventTopic command: ` + errMsg$1));
|
|
63
63
|
}
|
|
64
64
|
let hook$1 = EventPublish_Callback$ReventlessCore.afterPublishHook.contents;
|
|
65
65
|
if (hook$1 === undefined) {
|
|
@@ -80,15 +80,16 @@ function Make(MappingSpec) {
|
|
|
80
80
|
} catch (raw_err$2) {
|
|
81
81
|
let err$2 = Primitive_exceptions.internalToException(raw_err$2);
|
|
82
82
|
let errMsg$2 = Stdlib_Option.getOr(Stdlib_Option.flatMap(Stdlib_JsExn.fromException(err$2), Stdlib_JsExn.message), "unknown");
|
|
83
|
-
return Effect.runSync(EffectLogger$ReventlessCore.logError(`ExtensionPoint(` + MappingSpec.name + `)`, undefined, `afterPublishHook error: ` + errMsg$2));
|
|
83
|
+
return Effect.runSync(EffectLogger$ReventlessCore.logError(`ExtensionPoint(` + MappingSpec.name + `)`, undefined, undefined, `afterPublishHook error: ` + errMsg$2));
|
|
84
84
|
}
|
|
85
85
|
};
|
|
86
86
|
let applyEventAction = async action => {
|
|
87
87
|
switch (action.TAG) {
|
|
88
88
|
case "AbstractPublishEvent" :
|
|
89
89
|
let eventJson = action._2;
|
|
90
|
-
|
|
91
|
-
|
|
90
|
+
let meta = action._1;
|
|
91
|
+
Effect.runSync(EffectLogger$ReventlessCore.logInfo(`ExtensionPoint(` + MappingSpec.name + `)`, undefined, EffectLogger$ReventlessCore.idsOf(undefined, undefined, meta), `applying event: ` + LogFormat$ReventlessCore.eventSummary(eventJson)));
|
|
92
|
+
return await publishWithHooks(action._0, meta, eventJson);
|
|
92
93
|
case "AbstractPublishEventAsync" :
|
|
93
94
|
let match = await action._0;
|
|
94
95
|
return await publishWithHooks(match[0], match[1], match[2]);
|
|
@@ -98,7 +99,7 @@ function Make(MappingSpec) {
|
|
|
98
99
|
} catch (raw_err) {
|
|
99
100
|
let err = Primitive_exceptions.internalToException(raw_err);
|
|
100
101
|
let errMsg = Stdlib_Option.getOr(Stdlib_Option.flatMap(Stdlib_JsExn.fromException(err), Stdlib_JsExn.message), "unknown");
|
|
101
|
-
return Effect.runSync(EffectLogger$ReventlessCore.logError(`ExtensionPoint(` + MappingSpec.name + `)`, undefined, `Error on handling directive: ` + errMsg));
|
|
102
|
+
return Effect.runSync(EffectLogger$ReventlessCore.logError(`ExtensionPoint(` + MappingSpec.name + `)`, undefined, undefined, `Error on handling directive: ` + errMsg));
|
|
102
103
|
}
|
|
103
104
|
}
|
|
104
105
|
};
|
|
@@ -106,7 +107,7 @@ function Make(MappingSpec) {
|
|
|
106
107
|
if (Pii$Reventless.needsPrepare([eventJson$p])) {
|
|
107
108
|
await Pii$Reventless.prepareOrThrow([eventJson$p]);
|
|
108
109
|
}
|
|
109
|
-
Effect.runSync(EffectLogger$ReventlessCore.logInfo(`ExtensionPoint(` + MappingSpec.name + `)`, undefined, `outgoing event: ` + LogFormat$ReventlessCore.eventSummary(eventJson$p)));
|
|
110
|
+
Effect.runSync(EffectLogger$ReventlessCore.logInfo(`ExtensionPoint(` + MappingSpec.name + `)`, undefined, EffectLogger$ReventlessCore.idsOfJson(eventJson$p), `outgoing event: ` + LogFormat$ReventlessCore.eventSummary(eventJson$p)));
|
|
110
111
|
let eventActions = mapOutgoingEvent(eventJson$p, Mappings.mappings, Ops.scheduler, Ops.commandTopicResources, Ops.queryEngine, Ops.resourceNaming);
|
|
111
112
|
return await Util_Promise$ReventlessCore.toUnit(Promise.all(eventActions.map(applyEventAction)));
|
|
112
113
|
};
|
|
@@ -241,6 +241,10 @@ module Make = (
|
|
|
241
241
|
~caller: option<Reventless.Identity.t>=?,
|
|
242
242
|
~door: ReventlessInfra.InboundTranslationSlice.door=Mutation,
|
|
243
243
|
): ReventlessInfra.InboundTranslationSlice.receiveResult => {
|
|
244
|
+
let publishJsons = CommandSent.announcing(
|
|
245
|
+
~comp=`InboundTranslationSlice(${Spec.name})`,
|
|
246
|
+
publishJsons,
|
|
247
|
+
)
|
|
244
248
|
let requestId = Uuid.v4()
|
|
245
249
|
let callerId = caller->Option.map(identity => identity.userId)
|
|
246
250
|
let fail = (~errorCode=?, error) =>
|
|
@@ -19,6 +19,7 @@ import * as OwnerScope$Reventless from "@reventlessdev/reventless-spec/src/types
|
|
|
19
19
|
import * as Message$ReventlessCore from "../../Message.res.mjs";
|
|
20
20
|
import * as Authorization$Reventless from "@reventlessdev/reventless-spec/src/types/Authorization.res.mjs";
|
|
21
21
|
import * as CommandOutcome$Reventless from "@reventlessdev/reventless-spec/src/components/CommandOutcome.res.mjs";
|
|
22
|
+
import * as CommandSent$ReventlessCore from "../../CommandSent.res.mjs";
|
|
22
23
|
import * as EffectLogger$ReventlessCore from "../../util/EffectLogger.res.mjs";
|
|
23
24
|
import * as ApiNoApiHelpers$ReventlessCore from "../Api/ApiNoApiHelpers.res.mjs";
|
|
24
25
|
import * as InboundTranslationSlice$ReventlessInfra from "@reventlessdev/reventless-infra/src/components/InboundTranslationSlice.res.mjs";
|
|
@@ -183,7 +184,7 @@ function Make(Spec) {
|
|
|
183
184
|
};
|
|
184
185
|
} catch (raw_exn) {
|
|
185
186
|
let exn = Primitive_exceptions.internalToException(raw_exn);
|
|
186
|
-
Effect.runSync(EffectLogger$ReventlessCore.logError(`InboundTranslationSlice(` + Spec.name + `)`, undefined, `failed to encode command: ` + messageOf(exn, "unknown")));
|
|
187
|
+
Effect.runSync(EffectLogger$ReventlessCore.logError(`InboundTranslationSlice(` + Spec.name + `)`, undefined, undefined, `failed to encode command: ` + messageOf(exn, "unknown")));
|
|
187
188
|
return {
|
|
188
189
|
TAG: "Error",
|
|
189
190
|
_0: "failed to encode command"
|
|
@@ -192,6 +193,7 @@ function Make(Spec) {
|
|
|
192
193
|
};
|
|
193
194
|
let receive = async (publishJsons, inputJson, capabilities, caller, doorOpt) => {
|
|
194
195
|
let door = doorOpt !== undefined ? doorOpt : "Mutation";
|
|
196
|
+
let publishJsons$1 = CommandSent$ReventlessCore.announcing(`InboundTranslationSlice(` + Spec.name + `)`, publishJsons);
|
|
195
197
|
let requestId = Uuid.v4();
|
|
196
198
|
let callerId = Stdlib_Option.map(caller, identity => identity.userId);
|
|
197
199
|
let fail = (errorCode, error) => failWith(requestId, JSON.stringify(redactInput(inputJson, sensitive)), door, callerId, errorCode, error);
|
|
@@ -277,7 +279,7 @@ function Make(Spec) {
|
|
|
277
279
|
return succeed([]);
|
|
278
280
|
}
|
|
279
281
|
try {
|
|
280
|
-
await publishJsons(msgs);
|
|
282
|
+
await publishJsons$1(msgs);
|
|
281
283
|
return succeed(pairs.map(param => param[0]));
|
|
282
284
|
} catch (raw_exn$2) {
|
|
283
285
|
let exn$2 = Primitive_exceptions.internalToException(raw_exn$2);
|
|
@@ -260,7 +260,7 @@ async function serve(slice, secretOfOpt, nowSecondsOpt, request) {
|
|
|
260
260
|
return respond(await slice.refuse(request.body, "InvalidBody", "body is not JSON"));
|
|
261
261
|
}
|
|
262
262
|
}
|
|
263
|
-
Effect.runSync(EffectLogger$ReventlessCore.logError(`InboundTranslationSlice(` + slice.route.slice + `)`, undefined, `webhook secret ` + signed._0 + ` is not set; refusing every request`));
|
|
263
|
+
Effect.runSync(EffectLogger$ReventlessCore.logError(`InboundTranslationSlice(` + slice.route.slice + `)`, undefined, undefined, `webhook secret ` + signed._0 + ` is not set; refusing every request`));
|
|
264
264
|
return plain(500, "webhook is not configured");
|
|
265
265
|
}
|
|
266
266
|
|
|
@@ -116,7 +116,7 @@ function Make(RuntimeEnvironment) {
|
|
|
116
116
|
await syncToQueryDb(queryDbOps);
|
|
117
117
|
Stdlib_Promise.$$catch(Callback.phase2(publishJsonsFn, Capabilities.capabilities()).then(() => syncToQueryDb(queryDbOps)), exn => {
|
|
118
118
|
let errMsg = Stdlib_Option.getOr(Stdlib_Option.flatMap(Stdlib_JsExn.fromException(exn), Stdlib_JsExn.message), "unknown");
|
|
119
|
-
Effect.runSync(EffectLogger$ReventlessCore.logError(`OutboundTranslationSlice(` + Spec.name + `)`, undefined, `detached phase 2 error: ` + errMsg));
|
|
119
|
+
Effect.runSync(EffectLogger$ReventlessCore.logError(`OutboundTranslationSlice(` + Spec.name + `)`, undefined, undefined, `detached phase 2 error: ` + errMsg));
|
|
120
120
|
return Promise.resolve();
|
|
121
121
|
});
|
|
122
122
|
}));
|
|
@@ -203,6 +203,7 @@ module Make = (
|
|
|
203
203
|
exn->JsExn.fromException->Option.flatMap(JsExn.message)->Option.getOr("unknown")
|
|
204
204
|
EffectLogger.logError(
|
|
205
205
|
~comp=`OutboundTranslationSlice(${Spec.name})`,
|
|
206
|
+
~ids=?row.source->Option.map(EffectLogger.idsOfSource),
|
|
206
207
|
`retries exhausted for ${id}, and the abandonment command could not be published: ${errMsg}`,
|
|
207
208
|
)->Effect.runSync
|
|
208
209
|
}
|
|
@@ -210,6 +211,7 @@ module Make = (
|
|
|
210
211
|
| exception _ =>
|
|
211
212
|
EffectLogger.logError(
|
|
212
213
|
~comp=`OutboundTranslationSlice(${Spec.name})`,
|
|
214
|
+
~ids=?row.source->Option.map(EffectLogger.idsOfSource),
|
|
213
215
|
`retries exhausted for ${id}, and its item could not be decoded to announce it`,
|
|
214
216
|
)->Effect.runSync
|
|
215
217
|
}
|
|
@@ -278,6 +280,7 @@ module Make = (
|
|
|
278
280
|
| Error(e) =>
|
|
279
281
|
EffectLogger.logError(
|
|
280
282
|
~comp=`OutboundTranslationSlice(${Spec.name})`,
|
|
283
|
+
~ids=?source->Option.map(EffectLogger.idsOfSource),
|
|
281
284
|
`a work item was not stored: ${e->Reventless.Pii.errorMessage}`,
|
|
282
285
|
)->Effect.runSync
|
|
283
286
|
| Ok(stored) =>
|
|
@@ -299,6 +302,10 @@ module Make = (
|
|
|
299
302
|
publishJsons: ReventlessInfra.CommandTopic.publishJsons,
|
|
300
303
|
~capabilities: Reventless.Capabilities.t,
|
|
301
304
|
) => {
|
|
305
|
+
let publishJsons = CommandSent.announcing(
|
|
306
|
+
~comp=`OutboundTranslationSlice(${Spec.name})`,
|
|
307
|
+
publishJsons,
|
|
308
|
+
)
|
|
302
309
|
// Ids that ran out of budget during this pass, announced once at the end so
|
|
303
310
|
// one item's abandonment cannot interleave with another's attempt.
|
|
304
311
|
let newlyAbandoned: array<string> = []
|
|
@@ -345,6 +352,7 @@ module Make = (
|
|
|
345
352
|
| Error(#Gone(field)) =>
|
|
346
353
|
EffectLogger.logInfo(
|
|
347
354
|
~comp=`OutboundTranslationSlice(${Spec.name})`,
|
|
355
|
+
~ids=?row.source->Option.map(EffectLogger.idsOfSource),
|
|
348
356
|
`${id}: its ${field} was erased; nothing to do`,
|
|
349
357
|
)->Effect.runSync
|
|
350
358
|
todoItems->Dict.set(id, {...row, status: Completed, completedAt: now()})
|
|
@@ -352,6 +360,7 @@ module Make = (
|
|
|
352
360
|
| Error(#Unopened(why)) =>
|
|
353
361
|
EffectLogger.logError(
|
|
354
362
|
~comp=`OutboundTranslationSlice(${Spec.name})`,
|
|
363
|
+
~ids=?row.source->Option.map(EffectLogger.idsOfSource),
|
|
355
364
|
`${id}: its work item does not open: ${why}`,
|
|
356
365
|
)->Effect.runSync
|
|
357
366
|
let updated = row->afterFailedAttempt(~lastError=why)
|
|
@@ -367,6 +376,7 @@ module Make = (
|
|
|
367
376
|
exn->JsExn.fromException->Option.flatMap(JsExn.message)->Option.getOr("unknown")
|
|
368
377
|
EffectLogger.logError(
|
|
369
378
|
~comp=`OutboundTranslationSlice(${Spec.name})`,
|
|
379
|
+
~ids=?row.source->Option.map(EffectLogger.idsOfSource),
|
|
370
380
|
`failed to decode outboundItem: ${errMsg}`,
|
|
371
381
|
)->Effect.runSync
|
|
372
382
|
None
|
|
@@ -399,6 +409,7 @@ module Make = (
|
|
|
399
409
|
exn->JsExn.fromException->Option.flatMap(JsExn.message)->Option.getOr("unknown")
|
|
400
410
|
EffectLogger.logError(
|
|
401
411
|
~comp=`OutboundTranslationSlice(${Spec.name})`,
|
|
412
|
+
~ids=?row.source->Option.map(EffectLogger.idsOfSource),
|
|
402
413
|
`failed to encode inbound command: ${errMsg}`,
|
|
403
414
|
)->Effect.runSync
|
|
404
415
|
None
|
|
@@ -420,6 +431,7 @@ module Make = (
|
|
|
420
431
|
exn->JsExn.fromException->Option.flatMap(JsExn.message)->Option.getOr("unknown")
|
|
421
432
|
EffectLogger.logError(
|
|
422
433
|
~comp=`OutboundTranslationSlice(${Spec.name})`,
|
|
434
|
+
~ids=?row.source->Option.map(EffectLogger.idsOfSource),
|
|
423
435
|
`failed to publish command: ${errMsg}`,
|
|
424
436
|
)->Effect.runSync
|
|
425
437
|
let updated = row->afterFailedAttempt(~lastError=errMsg)
|
|
@@ -12,6 +12,7 @@ import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js
|
|
|
12
12
|
import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
|
|
13
13
|
import * as Util_Sury$Reventless from "@reventlessdev/reventless-spec/src/util/Util_Sury.res.mjs";
|
|
14
14
|
import * as Message$ReventlessCore from "../../Message.res.mjs";
|
|
15
|
+
import * as CommandSent$ReventlessCore from "../../CommandSent.res.mjs";
|
|
15
16
|
import * as EffectLogger$ReventlessCore from "../../util/EffectLogger.res.mjs";
|
|
16
17
|
|
|
17
18
|
let todoStatusSchema = Sury.union([
|
|
@@ -73,7 +74,7 @@ function Make(Spec) {
|
|
|
73
74
|
try {
|
|
74
75
|
item = Util_Sury$Reventless.fromJson(row.item, Spec.outboundItemSchema);
|
|
75
76
|
} catch (exn) {
|
|
76
|
-
return Effect.runSync(EffectLogger$ReventlessCore.logError(`OutboundTranslationSlice(` + Spec.name + `)`, undefined, `retries exhausted for ` + id + `, and its item could not be decoded to announce it`));
|
|
77
|
+
return Effect.runSync(EffectLogger$ReventlessCore.logError(`OutboundTranslationSlice(` + Spec.name + `)`, undefined, Stdlib_Option.map(row.source, EffectLogger$ReventlessCore.idsOfSource), `retries exhausted for ` + id + `, and its item could not be decoded to announce it`));
|
|
77
78
|
}
|
|
78
79
|
let match = Translation.onExhausted(id, item, row.lastError);
|
|
79
80
|
if (match === undefined) {
|
|
@@ -92,7 +93,7 @@ function Make(Spec) {
|
|
|
92
93
|
} catch (raw_exn) {
|
|
93
94
|
let exn$1 = Primitive_exceptions.internalToException(raw_exn);
|
|
94
95
|
let errMsg = Stdlib_Option.getOr(Stdlib_Option.flatMap(Stdlib_JsExn.fromException(exn$1), Stdlib_JsExn.message), "unknown");
|
|
95
|
-
return Effect.runSync(EffectLogger$ReventlessCore.logError(`OutboundTranslationSlice(` + Spec.name + `)`, undefined, `retries exhausted for ` + id + `, and the abandonment command could not be published: ` + errMsg));
|
|
96
|
+
return Effect.runSync(EffectLogger$ReventlessCore.logError(`OutboundTranslationSlice(` + Spec.name + `)`, undefined, Stdlib_Option.map(row.source, EffectLogger$ReventlessCore.idsOfSource), `retries exhausted for ` + id + `, and the abandonment command could not be published: ` + errMsg));
|
|
96
97
|
}
|
|
97
98
|
};
|
|
98
99
|
let personalFields = Pii$Reventless.recordFields(Spec.outboundItemSchema);
|
|
@@ -110,12 +111,12 @@ function Make(Spec) {
|
|
|
110
111
|
}
|
|
111
112
|
let why = fingerprint._0._0;
|
|
112
113
|
if (Pii$Reventless.Provider.isRequired()) {
|
|
113
|
-
Effect.runSync(EffectLogger$ReventlessCore.logError(`OutboundTranslationSlice(` + Spec.name + `)`, undefined, `a work item was not stored: its row id cannot be fingerprinted (` + why + `)`));
|
|
114
|
+
Effect.runSync(EffectLogger$ReventlessCore.logError(`OutboundTranslationSlice(` + Spec.name + `)`, undefined, undefined, `a work item was not stored: its row id cannot be fingerprinted (` + why + `)`));
|
|
114
115
|
return;
|
|
115
116
|
} else {
|
|
116
117
|
if (!warnedUnkeyed.contents) {
|
|
117
118
|
warnedUnkeyed.contents = true;
|
|
118
|
-
Effect.runSync(EffectLogger$ReventlessCore.logWarn(`OutboundTranslationSlice(` + Spec.name + `)`, undefined, `work items carrying personal data are keyed in the clear: no key to fingerprint them with (` + why + `)`));
|
|
119
|
+
Effect.runSync(EffectLogger$ReventlessCore.logWarn(`OutboundTranslationSlice(` + Spec.name + `)`, undefined, undefined, `work items carrying personal data are keyed in the clear: no key to fingerprint them with (` + why + `)`));
|
|
119
120
|
}
|
|
120
121
|
return key;
|
|
121
122
|
}
|
|
@@ -150,13 +151,14 @@ function Make(Spec) {
|
|
|
150
151
|
};
|
|
151
152
|
todoItems[id] = row;
|
|
152
153
|
} else {
|
|
153
|
-
Effect.runSync(EffectLogger$ReventlessCore.logError(`OutboundTranslationSlice(` + Spec.name + `)`, undefined, `a work item was not stored: ` + Pii$Reventless.errorMessage(stored._0)));
|
|
154
|
+
Effect.runSync(EffectLogger$ReventlessCore.logError(`OutboundTranslationSlice(` + Spec.name + `)`, undefined, Stdlib_Option.map(source, EffectLogger$ReventlessCore.idsOfSource), `a work item was not stored: ` + Pii$Reventless.errorMessage(stored._0)));
|
|
154
155
|
}
|
|
155
156
|
}
|
|
156
157
|
}
|
|
157
158
|
}
|
|
158
159
|
};
|
|
159
160
|
let phase2 = async (publishJsons, capabilities) => {
|
|
161
|
+
let publishJsons$1 = CommandSent$ReventlessCore.announcing(`OutboundTranslationSlice(` + Spec.name + `)`, publishJsons);
|
|
160
162
|
let newlyAbandoned = [];
|
|
161
163
|
Object.entries(todoItems).forEach(param => {
|
|
162
164
|
let row = param[1];
|
|
@@ -222,13 +224,13 @@ function Make(Spec) {
|
|
|
222
224
|
} catch (raw_exn) {
|
|
223
225
|
let exn = Primitive_exceptions.internalToException(raw_exn);
|
|
224
226
|
let errMsg = Stdlib_Option.getOr(Stdlib_Option.flatMap(Stdlib_JsExn.fromException(exn), Stdlib_JsExn.message), "unknown");
|
|
225
|
-
Effect.runSync(EffectLogger$ReventlessCore.logError(`OutboundTranslationSlice(` + Spec.name + `)`, undefined, `failed to decode outboundItem: ` + errMsg));
|
|
227
|
+
Effect.runSync(EffectLogger$ReventlessCore.logError(`OutboundTranslationSlice(` + Spec.name + `)`, undefined, Stdlib_Option.map(row.source, EffectLogger$ReventlessCore.idsOfSource), `failed to decode outboundItem: ` + errMsg));
|
|
226
228
|
item = undefined;
|
|
227
229
|
}
|
|
228
230
|
} else {
|
|
229
231
|
let match = opened._0;
|
|
230
232
|
if (match.NAME === "Gone") {
|
|
231
|
-
Effect.runSync(EffectLogger$ReventlessCore.logInfo(`OutboundTranslationSlice(` + Spec.name + `)`, undefined, id + `: its ` + match.VAL + ` was erased; nothing to do`));
|
|
233
|
+
Effect.runSync(EffectLogger$ReventlessCore.logInfo(`OutboundTranslationSlice(` + Spec.name + `)`, undefined, Stdlib_Option.map(row.source, EffectLogger$ReventlessCore.idsOfSource), id + `: its ` + match.VAL + ` was erased; nothing to do`));
|
|
232
234
|
let newrecord = {...row};
|
|
233
235
|
newrecord.completedAt = new Date().toISOString();
|
|
234
236
|
newrecord.status = "Completed";
|
|
@@ -236,7 +238,7 @@ function Make(Spec) {
|
|
|
236
238
|
item = undefined;
|
|
237
239
|
} else {
|
|
238
240
|
let why = match.VAL;
|
|
239
|
-
Effect.runSync(EffectLogger$ReventlessCore.logError(`OutboundTranslationSlice(` + Spec.name + `)`, undefined, id + `: its work item does not open: ` + why));
|
|
241
|
+
Effect.runSync(EffectLogger$ReventlessCore.logError(`OutboundTranslationSlice(` + Spec.name + `)`, undefined, Stdlib_Option.map(row.source, EffectLogger$ReventlessCore.idsOfSource), id + `: its work item does not open: ` + why));
|
|
240
242
|
let updated = afterFailedAttempt(row, why);
|
|
241
243
|
todoItems[id] = updated;
|
|
242
244
|
if (updated.status === "Abandoned") {
|
|
@@ -272,7 +274,7 @@ function Make(Spec) {
|
|
|
272
274
|
} catch (raw_exn$2) {
|
|
273
275
|
let exn$2 = Primitive_exceptions.internalToException(raw_exn$2);
|
|
274
276
|
let errMsg$1 = Stdlib_Option.getOr(Stdlib_Option.flatMap(Stdlib_JsExn.fromException(exn$2), Stdlib_JsExn.message), "unknown");
|
|
275
|
-
Effect.runSync(EffectLogger$ReventlessCore.logError(`OutboundTranslationSlice(` + Spec.name + `)`, undefined, `failed to encode inbound command: ` + errMsg$1));
|
|
277
|
+
Effect.runSync(EffectLogger$ReventlessCore.logError(`OutboundTranslationSlice(` + Spec.name + `)`, undefined, Stdlib_Option.map(row.source, EffectLogger$ReventlessCore.idsOfSource), `failed to encode inbound command: ` + errMsg$1));
|
|
276
278
|
commandJson = undefined;
|
|
277
279
|
}
|
|
278
280
|
if (commandJson !== undefined) {
|
|
@@ -284,7 +286,7 @@ function Make(Spec) {
|
|
|
284
286
|
meta: msg_meta,
|
|
285
287
|
commandJson: commandJson
|
|
286
288
|
};
|
|
287
|
-
await publishJsons([msg$1]);
|
|
289
|
+
await publishJsons$1([msg$1]);
|
|
288
290
|
let newrecord$2 = {...row};
|
|
289
291
|
newrecord$2.completedAt = new Date().toISOString();
|
|
290
292
|
newrecord$2.status = "Completed";
|
|
@@ -293,7 +295,7 @@ function Make(Spec) {
|
|
|
293
295
|
} catch (raw_exn$3) {
|
|
294
296
|
let exn$3 = Primitive_exceptions.internalToException(raw_exn$3);
|
|
295
297
|
let errMsg$2 = Stdlib_Option.getOr(Stdlib_Option.flatMap(Stdlib_JsExn.fromException(exn$3), Stdlib_JsExn.message), "unknown");
|
|
296
|
-
Effect.runSync(EffectLogger$ReventlessCore.logError(`OutboundTranslationSlice(` + Spec.name + `)`, undefined, `failed to publish command: ` + errMsg$2));
|
|
298
|
+
Effect.runSync(EffectLogger$ReventlessCore.logError(`OutboundTranslationSlice(` + Spec.name + `)`, undefined, Stdlib_Option.map(row.source, EffectLogger$ReventlessCore.idsOfSource), `failed to publish command: ` + errMsg$2));
|
|
297
299
|
let updated$1 = afterFailedAttempt(row, errMsg$2);
|
|
298
300
|
todoItems[id] = updated$1;
|
|
299
301
|
if (updated$1.status === "Abandoned") {
|
|
@@ -335,7 +337,7 @@ function Make(Spec) {
|
|
|
335
337
|
await prev;
|
|
336
338
|
let row = todoItems[id];
|
|
337
339
|
if (row !== undefined) {
|
|
338
|
-
return await announceAbandonment(id, row, publishJsons);
|
|
340
|
+
return await announceAbandonment(id, row, publishJsons$1);
|
|
339
341
|
}
|
|
340
342
|
});
|
|
341
343
|
};
|
|
@@ -129,6 +129,7 @@ module Make = (ReadModelSpec: Reventless.ReadModel.Spec, Ops: Ops) => {
|
|
|
129
129
|
injectSubId(dict, state)
|
|
130
130
|
injectCompositeIndexAttrs(dict)
|
|
131
131
|
stampUnionMembers(dict)
|
|
132
|
+
RowChange.stampInto(dict)
|
|
132
133
|
let json = JSON.Encode.object(dict)
|
|
133
134
|
await Ops.jsonOps.save(id->ReadModelSpec.Id.toString, json, saveMode, ttl)
|
|
134
135
|
| None =>
|
|
@@ -144,6 +145,7 @@ module Make = (ReadModelSpec: Reventless.ReadModel.Spec, Ops: Ops) => {
|
|
|
144
145
|
injectSubId(dict, state)
|
|
145
146
|
injectCompositeIndexAttrs(dict)
|
|
146
147
|
stampUnionMembers(dict)
|
|
148
|
+
RowChange.stampInto(dict)
|
|
147
149
|
let json = JSON.Encode.object(dict)
|
|
148
150
|
Ok(batch->Array.concat([(id->ReadModelSpec.Id.toString, json, ttl)]))
|
|
149
151
|
| None =>
|
|
@@ -10,6 +10,7 @@ import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_excep
|
|
|
10
10
|
import * as Logger$ReventlessCore from "../../util/Logger.res.mjs";
|
|
11
11
|
import * as Message$ReventlessCore from "../../Message.res.mjs";
|
|
12
12
|
import * as TaggedUnion$Reventless from "@reventlessdev/reventless-spec/src/components/TaggedUnion.res.mjs";
|
|
13
|
+
import * as RowChange$ReventlessCore from "../../RowChange.res.mjs";
|
|
13
14
|
|
|
14
15
|
let log = Logger$ReventlessCore.fromEnv();
|
|
15
16
|
|
|
@@ -104,6 +105,7 @@ function Make(ReadModelSpec) {
|
|
|
104
105
|
injectSubId(dict, state);
|
|
105
106
|
injectCompositeIndexAttrs(dict);
|
|
106
107
|
stampUnionMembers(dict);
|
|
108
|
+
RowChange$ReventlessCore.stampInto(dict);
|
|
107
109
|
return await Ops.jsonOps.save(ReadModelSpec.Id.toString(id), dict, saveMode, ttl);
|
|
108
110
|
} else {
|
|
109
111
|
return {
|
|
@@ -130,6 +132,7 @@ function Make(ReadModelSpec) {
|
|
|
130
132
|
injectSubId(dict, state);
|
|
131
133
|
injectCompositeIndexAttrs(dict);
|
|
132
134
|
stampUnionMembers(dict);
|
|
135
|
+
RowChange$ReventlessCore.stampInto(dict);
|
|
133
136
|
return {
|
|
134
137
|
TAG: "Ok",
|
|
135
138
|
_0: batch.concat([[
|
|
@@ -31,6 +31,7 @@ module Make = (
|
|
|
31
31
|
let idxStr = (idx + 1)->Int.toString
|
|
32
32
|
EffectLogger.logInfo(
|
|
33
33
|
~comp,
|
|
34
|
+
~ids=EffectLogger.idsOf(context.meta, ~entityId=context.id, ~entityType=sourceName),
|
|
34
35
|
~detail=json,
|
|
35
36
|
`handling event ${idxStr}/${total} from ${sourceName}: ${LogFormat.eventDetail(
|
|
36
37
|
json,
|
|
@@ -30,7 +30,7 @@ function Make(ReadModelSpec) {
|
|
|
30
30
|
let actions = EventProjector.map(sourceName, json);
|
|
31
31
|
let actionsStr = LogFormat$ReventlessCore.actionNames(actions);
|
|
32
32
|
let idxStr = (idx + 1 | 0).toString();
|
|
33
|
-
Effect.runSync(EffectLogger$ReventlessCore.logInfo(comp, json, `handling event ` + idxStr + `/` + total + ` from ` + sourceName + `: ` + LogFormat$ReventlessCore.eventDetail(json) + ` actions:` + actionsStr));
|
|
33
|
+
Effect.runSync(EffectLogger$ReventlessCore.logInfo(comp, json, EffectLogger$ReventlessCore.idsOf(context.id, sourceName, context.meta), `handling event ` + idxStr + `/` + total + ` from ` + sourceName + `: ` + LogFormat$ReventlessCore.eventDetail(json) + ` actions:` + actionsStr));
|
|
34
34
|
let sources = [ViewChange$ReventlessCore.sourceOf(context.meta, context.id, sourceName, undefined)];
|
|
35
35
|
return actions.map(action => [
|
|
36
36
|
Projection$ReventlessCore.rewriteAction(action, context.meta.time, ReadModelSpec.stateSchema),
|
|
@@ -72,6 +72,7 @@ module Make = (Spec: Spec): T => {
|
|
|
72
72
|
let sourceName = SideEffect.Source.name
|
|
73
73
|
EffectLogger.logInfo(
|
|
74
74
|
~comp="SideEffectHandler",
|
|
75
|
+
~ids=EffectLogger.idsOf(eventMeta),
|
|
75
76
|
`eventsHandler: handling event from source ${sourceName}: ${LogFormat.event'JsonToLogMessage(
|
|
76
77
|
eventJson',
|
|
77
78
|
)}`,
|
|
@@ -106,6 +107,7 @@ module Make = (Spec: Spec): T => {
|
|
|
106
107
|
| _ =>
|
|
107
108
|
EffectLogger.logError(
|
|
108
109
|
~comp="SideEffectHandler",
|
|
110
|
+
~ids=EffectLogger.idsOf(eventMeta),
|
|
109
111
|
`eventHandler: Invalid event ${eventJson'->JSON.stringify}`,
|
|
110
112
|
)
|
|
111
113
|
}
|
|
@@ -28,7 +28,7 @@ function Make(Spec) {
|
|
|
28
28
|
} catch (raw_err) {
|
|
29
29
|
let err = Primitive_exceptions.internalToException(raw_err);
|
|
30
30
|
let errMsg = Stdlib_Option.getOr(Stdlib_Option.flatMap(Stdlib_JsExn.fromException(err), Stdlib_JsExn.message), "unknown");
|
|
31
|
-
Effect$1.runSync(EffectLogger$ReventlessCore.logError("SideEffects", undefined, `map: Couldn't decode meta: ` + errMsg));
|
|
31
|
+
Effect$1.runSync(EffectLogger$ReventlessCore.logError("SideEffects", undefined, undefined, `map: Couldn't decode meta: ` + errMsg));
|
|
32
32
|
return;
|
|
33
33
|
}
|
|
34
34
|
if (eventMeta !== undefined) {
|
|
@@ -47,7 +47,7 @@ function Make(Spec) {
|
|
|
47
47
|
return;
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
|
-
Effect$1.runSync(EffectLogger$ReventlessCore.logError("SideEffects", undefined, "map: Invalid JSON object"));
|
|
50
|
+
Effect$1.runSync(EffectLogger$ReventlessCore.logError("SideEffects", undefined, undefined, "map: Invalid JSON object"));
|
|
51
51
|
});
|
|
52
52
|
let handleJsonEvents = stream => Stream.runDrain(Stream.mapEffect(stream, eventJson$p => {
|
|
53
53
|
let match = findSideEffect(sideEffectsWithTags, eventJson$p);
|
|
@@ -58,7 +58,7 @@ function Make(Spec) {
|
|
|
58
58
|
let eventMeta = match[1];
|
|
59
59
|
let eventObj = match[0];
|
|
60
60
|
let sourceName = sideEffect.Source.name;
|
|
61
|
-
return Effect$1.zipRight(EffectLogger$ReventlessCore.logInfo("SideEffectHandler", undefined, `eventsHandler: handling event from source ` + sourceName + `: ` + LogFormat$ReventlessCore.event$pJsonToLogMessage(eventJson$p)), Effect$1.catchAll(Effect$1.flatMap(Effect.trySync(err => {
|
|
61
|
+
return Effect$1.zipRight(EffectLogger$ReventlessCore.logInfo("SideEffectHandler", undefined, EffectLogger$ReventlessCore.idsOf(undefined, undefined, eventMeta), `eventsHandler: handling event from source ` + sourceName + `: ` + LogFormat$ReventlessCore.event$pJsonToLogMessage(eventJson$p)), Effect$1.catchAll(Effect$1.flatMap(Effect.trySync(err => {
|
|
62
62
|
let errMsg = Util_Error$ReventlessCore.messageFromUnknown(err, "unknown");
|
|
63
63
|
return `SideEffectHandler.eventHandler: Couldn't decode event: ` + JSON.stringify(eventJson$p) + ` ` + errMsg;
|
|
64
64
|
}, () => {
|
|
@@ -78,11 +78,11 @@ function Make(Spec) {
|
|
|
78
78
|
return Effect$1.catchAll(Effect.tryPromise(err => {
|
|
79
79
|
let errMsg = Util_Error$ReventlessCore.messageFromUnknown(err, "unknown");
|
|
80
80
|
return `SideEffect: Error while processing: ` + errMsg;
|
|
81
|
-
}, () => sideEffect.execute(eventId$1, eventMeta, event$1, Spec.queryEngine)), errMsg => EffectLogger$ReventlessCore.logError("SideEffectHandler", undefined, errMsg));
|
|
81
|
+
}, () => sideEffect.execute(eventId$1, eventMeta, event$1, Spec.queryEngine)), errMsg => EffectLogger$ReventlessCore.logError("SideEffectHandler", undefined, undefined, errMsg));
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
|
-
return EffectLogger$ReventlessCore.logError("SideEffectHandler", undefined, `eventHandler: Invalid event ` + JSON.stringify(eventJson$p));
|
|
85
|
-
}), errMsg => EffectLogger$ReventlessCore.logError("SideEffectHandler", undefined, errMsg)));
|
|
84
|
+
return EffectLogger$ReventlessCore.logError("SideEffectHandler", undefined, EffectLogger$ReventlessCore.idsOf(undefined, undefined, eventMeta), `eventHandler: Invalid event ` + JSON.stringify(eventJson$p));
|
|
85
|
+
}), errMsg => EffectLogger$ReventlessCore.logError("SideEffectHandler", undefined, undefined, errMsg)));
|
|
86
86
|
}));
|
|
87
87
|
return {
|
|
88
88
|
handleJsonEvents: handleJsonEvents
|
|
@@ -267,6 +267,7 @@ module Make = (
|
|
|
267
267
|
// the fields, so a leading `(id)` would just duplicate it.
|
|
268
268
|
EffectLogger.logInfo(
|
|
269
269
|
~comp,
|
|
270
|
+
~ids=EffectLogger.idsOf(cmdJson.meta),
|
|
270
271
|
~detail=cmdJson.commandJson,
|
|
271
272
|
`handling command: ${cmdJson->LogFormat.cmdDetailNoId}`,
|
|
272
273
|
)->Effect.runSync
|
|
@@ -300,7 +301,11 @@ module Make = (
|
|
|
300
301
|
tags == "" ? types : `${types}{${tags}}`
|
|
301
302
|
})
|
|
302
303
|
->Array.join(" OR ")
|
|
303
|
-
EffectLogger.logInfo(
|
|
304
|
+
EffectLogger.logInfo(
|
|
305
|
+
~comp,
|
|
306
|
+
~ids=EffectLogger.idsOf(cmdJson.meta),
|
|
307
|
+
`query: ${queryDetail}`,
|
|
308
|
+
)->Effect.runSync
|
|
304
309
|
|
|
305
310
|
// Extract the entity ID from the command for use in Accepted outcomes.
|
|
306
311
|
let entityId = switch partitionTag {
|
|
@@ -310,6 +315,12 @@ module Make = (
|
|
|
310
315
|
| Some(Simple(pt)) => Reventless.DcbTag.getPartitionTagValue(query, pt)
|
|
311
316
|
| Some(ByEventType(_)) | None => None
|
|
312
317
|
}
|
|
318
|
+
// The lines of this command name it and, for a simple partition, the entity it decides on:
|
|
319
|
+
// the partition tag's key and value, as a row change names a DCB event's entity.
|
|
320
|
+
let ids = switch partitionTag {
|
|
321
|
+
| Some(Simple(pt)) => EffectLogger.idsOf(cmdJson.meta, ~entityId?, ~entityType=pt.key)
|
|
322
|
+
| _ => EffectLogger.idsOf(cmdJson.meta)
|
|
323
|
+
}
|
|
313
324
|
|
|
314
325
|
// The owner fields of a read event, when it lies in this command's own
|
|
315
326
|
// partition. A cross-partition read (a catalog product) never says who owns
|
|
@@ -451,6 +462,7 @@ module Make = (
|
|
|
451
462
|
}
|
|
452
463
|
EffectLogger.logInfo(
|
|
453
464
|
~comp,
|
|
465
|
+
~ids,
|
|
454
466
|
`read${cacheHit ? " (cached, delta)" : ""}: ${reads
|
|
455
467
|
->Array.length
|
|
456
468
|
->Int.toString} event(s)${reads->Array.length == 0
|
|
@@ -464,6 +476,7 @@ module Make = (
|
|
|
464
476
|
// how long the entity has been in use.
|
|
465
477
|
EffectLogger.logDebug(
|
|
466
478
|
~comp,
|
|
479
|
+
~ids,
|
|
467
480
|
`deciding: id=${entityId->Option.getOr("-")} head=${headPosition->Option.getOr(
|
|
468
481
|
"-",
|
|
469
482
|
)} cmd=${cmdJson->LogFormat.cmdName}`,
|
|
@@ -476,6 +489,7 @@ module Make = (
|
|
|
476
489
|
CommandTopic_Helpers.reportAccepted(
|
|
477
490
|
~component=Spec.name,
|
|
478
491
|
~correlationId=cmdJson.meta.correlationId,
|
|
492
|
+
~causationId=?cmdJson.meta.causationId,
|
|
479
493
|
cmdJson.meta.msgId,
|
|
480
494
|
switch entityId {
|
|
481
495
|
| Some(eid) => {entityId: eid, eventCount: 0}
|
|
@@ -484,6 +498,7 @@ module Make = (
|
|
|
484
498
|
)
|
|
485
499
|
EffectLogger.logInfo(
|
|
486
500
|
~comp,
|
|
501
|
+
~ids,
|
|
487
502
|
`repeat dropped: ${cmdJson->LogFormat.cmdName} msgId=${cmdJson.meta.msgId} already caused events in id=${entityId->Option.getOr(
|
|
488
503
|
"-",
|
|
489
504
|
)}`,
|
|
@@ -494,6 +509,7 @@ module Make = (
|
|
|
494
509
|
CommandTopic_Helpers.reportRejected(
|
|
495
510
|
~component=Spec.name,
|
|
496
511
|
~correlationId=cmdJson.meta.correlationId,
|
|
512
|
+
~causationId=?cmdJson.meta.causationId,
|
|
497
513
|
~cause=AccessRefusal,
|
|
498
514
|
cmdJson.meta.msgId,
|
|
499
515
|
rejected,
|
|
@@ -501,7 +517,9 @@ module Make = (
|
|
|
501
517
|
let line = `refused: ${rejected.errorDetail} id=${entityId->Option.getOr("-")}`
|
|
502
518
|
|
|
503
519
|
(
|
|
504
|
-
isDefect
|
|
520
|
+
isDefect
|
|
521
|
+
? EffectLogger.logError(~comp, ~ids, line)
|
|
522
|
+
: EffectLogger.logWarn(~comp, ~ids, line)
|
|
505
523
|
)->Effect.map(_ => Ok("rejected"))
|
|
506
524
|
| None =>
|
|
507
525
|
switch Decision.decide(state, command'.command) {
|
|
@@ -511,13 +529,14 @@ module Make = (
|
|
|
511
529
|
CommandTopic_Helpers.reportAccepted(
|
|
512
530
|
~component=Spec.name,
|
|
513
531
|
~correlationId=cmdJson.meta.correlationId,
|
|
532
|
+
~causationId=?cmdJson.meta.causationId,
|
|
514
533
|
cmdJson.meta.msgId,
|
|
515
534
|
switch entityId {
|
|
516
535
|
| Some(eid) => {entityId: eid, eventCount: 0}
|
|
517
536
|
| None => {eventCount: 0}
|
|
518
537
|
},
|
|
519
538
|
)
|
|
520
|
-
EffectLogger.logInfo(~comp, "no events produced")->Effect.map(_ => Ok("ok"))
|
|
539
|
+
EffectLogger.logInfo(~comp, ~ids, "no events produced")->Effect.map(_ => Ok("ok"))
|
|
521
540
|
| Ok(newEvents) =>
|
|
522
541
|
let encoded =
|
|
523
542
|
newEvents->Array.map(
|
|
@@ -533,6 +552,7 @@ module Make = (
|
|
|
533
552
|
CommandTopic_Helpers.reportRejected(
|
|
534
553
|
~component=Spec.name,
|
|
535
554
|
~correlationId=cmdJson.meta.correlationId,
|
|
555
|
+
~causationId=?cmdJson.meta.causationId,
|
|
536
556
|
~cause=InfrastructureFailure,
|
|
537
557
|
cmdJson.meta.msgId,
|
|
538
558
|
{
|
|
@@ -540,7 +560,7 @@ module Make = (
|
|
|
540
560
|
errorDetail: detail,
|
|
541
561
|
},
|
|
542
562
|
)
|
|
543
|
-
EffectLogger.logError(~comp, `append refused: ${detail}`)->Effect.map(
|
|
563
|
+
EffectLogger.logError(~comp, ~ids, `append refused: ${detail}`)->Effect.map(
|
|
544
564
|
_ => Error(detail),
|
|
545
565
|
)
|
|
546
566
|
| Ok(rawEvents) =>
|
|
@@ -564,6 +584,7 @@ module Make = (
|
|
|
564
584
|
}
|
|
565
585
|
EffectLogger.logInfo(
|
|
566
586
|
~comp,
|
|
587
|
+
~ids,
|
|
567
588
|
~detail=eventJsons,
|
|
568
589
|
`produced ${eventCount} event(s): [${eventDetails}]`,
|
|
569
590
|
)
|
|
@@ -581,15 +602,18 @@ module Make = (
|
|
|
581
602
|
CommandTopic_Helpers.reportAccepted(
|
|
582
603
|
~component=Spec.name,
|
|
583
604
|
~correlationId=cmdJson.meta.correlationId,
|
|
605
|
+
~causationId=?cmdJson.meta.causationId,
|
|
584
606
|
cmdJson.meta.msgId,
|
|
585
607
|
switch entityId {
|
|
586
608
|
| Some(eid) => {entityId: eid, eventCount: rawEvents->Array.length}
|
|
587
609
|
| None => {eventCount: rawEvents->Array.length}
|
|
588
610
|
},
|
|
589
611
|
)
|
|
590
|
-
EffectLogger.logInfo(
|
|
591
|
-
|
|
592
|
-
|
|
612
|
+
EffectLogger.logInfo(
|
|
613
|
+
~comp,
|
|
614
|
+
~ids,
|
|
615
|
+
`append: ${eventCount} event(s)`,
|
|
616
|
+
)->Effect.map(_ => Ok("ok"))
|
|
593
617
|
| Error(err) =>
|
|
594
618
|
// Typed classification (was substring-matching the error string,
|
|
595
619
|
// which disagreed with the backends' casing).
|
|
@@ -613,6 +637,7 @@ module Make = (
|
|
|
613
637
|
Metrics.emitCount(~metric="AppendRetry", ~slice=Spec.name)
|
|
614
638
|
EffectLogger.logWarn(
|
|
615
639
|
~comp,
|
|
640
|
+
~ids,
|
|
616
641
|
`append failed (retrying ${(maxRetries - retries + 1)
|
|
617
642
|
->Int.toString}/${maxRetries->Int.toString}): ${errDetail}`,
|
|
618
643
|
)->Effect.flatMap(_ => attempt(~retries=retries - 1))
|
|
@@ -633,12 +658,14 @@ module Make = (
|
|
|
633
658
|
CommandTopic_Helpers.reportRejected(
|
|
634
659
|
~component=Spec.name,
|
|
635
660
|
~correlationId=cmdJson.meta.correlationId,
|
|
661
|
+
~causationId=?cmdJson.meta.causationId,
|
|
636
662
|
~cause=InfrastructureFailure,
|
|
637
663
|
cmdJson.meta.msgId,
|
|
638
664
|
{errorCode, errorDetail: errDetail},
|
|
639
665
|
)
|
|
640
666
|
EffectLogger.logError(
|
|
641
667
|
~comp,
|
|
668
|
+
~ids,
|
|
642
669
|
`append failed, retries exhausted: ${errDetail}`,
|
|
643
670
|
)->Effect.map(_ => Error(errDetail))
|
|
644
671
|
}
|
|
@@ -659,12 +686,14 @@ module Make = (
|
|
|
659
686
|
CommandTopic_Helpers.reportRejected(
|
|
660
687
|
~component=Spec.name,
|
|
661
688
|
~correlationId=cmdJson.meta.correlationId,
|
|
689
|
+
~causationId=?cmdJson.meta.causationId,
|
|
662
690
|
~cause=DomainRejection,
|
|
663
691
|
cmdJson.meta.msgId,
|
|
664
692
|
{errorCode, errorDetail},
|
|
665
693
|
)
|
|
666
694
|
EffectLogger.logError(
|
|
667
695
|
~comp,
|
|
696
|
+
~ids,
|
|
668
697
|
`decide rejected: ${errorCode} ${errorDetail}`,
|
|
669
698
|
)->Effect.map(_ => Ok("rejected"))
|
|
670
699
|
}
|