@reventlessdev/reventless-core 3.0.0-alpha.334 → 3.0.0-alpha.335

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.
Files changed (36) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/package.json +4 -4
  3. package/src/CommandSent.res +10 -0
  4. package/src/CommandSent.res.mjs +8 -0
  5. package/src/components/Aggregate/Aggregate_Callback.res +3 -0
  6. package/src/components/Aggregate/Aggregate_Callback.res.mjs +3 -3
  7. package/src/components/AutomationSlice/AutomationSlice.res +3 -0
  8. package/src/components/AutomationSlice/AutomationSlice_Builder.res +24 -8
  9. package/src/components/AutomationSlice/AutomationSlice_Builder.res.mjs +109 -102
  10. package/src/components/AutomationSlice/AutomationSlice_Callback.res +75 -8
  11. package/src/components/AutomationSlice/AutomationSlice_Callback.res.mjs +58 -7
  12. package/src/components/CommandGenerator/CommandGenerator_Callback.res.mjs +1 -1
  13. package/src/components/CommandTopic/CommandTopic.res.mjs +9 -0
  14. package/src/components/CommandTopic/CommandTopic_Helpers.res +118 -33
  15. package/src/components/CommandTopic/CommandTopic_Helpers.res.mjs +137 -22
  16. package/src/components/Dcb/Dcb_Builder.res +16 -0
  17. package/src/components/Dcb/Dcb_Builder.res.mjs +6 -3
  18. package/src/components/InboundTranslationSlice/InboundTranslationSlice.res +3 -0
  19. package/src/components/InboundTranslationSlice/InboundTranslationSlice_Builder.res +17 -6
  20. package/src/components/InboundTranslationSlice/InboundTranslationSlice_Builder.res.mjs +46 -41
  21. package/src/components/InboundTranslationSlice/InboundTranslationSlice_Callback.res +37 -8
  22. package/src/components/InboundTranslationSlice/InboundTranslationSlice_Callback.res.mjs +33 -13
  23. package/src/components/InboundTranslationSlice/InboundTranslationSlice_Webhook.res +3 -0
  24. package/src/components/InboundTranslationSlice/InboundTranslationSlice_Webhook.res.mjs +14 -2
  25. package/src/components/OutboundTranslationSlice/OutboundTranslationSlice.res +3 -0
  26. package/src/components/OutboundTranslationSlice/OutboundTranslationSlice_Builder.res +30 -9
  27. package/src/components/OutboundTranslationSlice/OutboundTranslationSlice_Builder.res.mjs +10 -5
  28. package/src/components/OutboundTranslationSlice/OutboundTranslationSlice_Callback.res +40 -2
  29. package/src/components/OutboundTranslationSlice/OutboundTranslationSlice_Callback.res.mjs +57 -11
  30. package/src/components/StateChangeSlice/StateChangeSlice_Callback.res +4 -0
  31. package/src/components/StateChangeSlice/StateChangeSlice_Callback.res.mjs +4 -4
  32. package/tests/commandtopic/CommandOutcomeLineTest.res.mjs +3 -3
  33. package/tests/commandtopic/CommandTopicHelpersRejectionTest.res +102 -0
  34. package/tests/commandtopic/CommandTopicHelpersRejectionTest.res.mjs +101 -3
  35. package/tests/plugin/PluginStructureAccessTest.res +6 -1
  36. package/tests/plugin/PluginStructureAccessTest.res.mjs +1 -1
package/CHANGELOG.md CHANGED
@@ -3,6 +3,22 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # 3.0.0-alpha.335 (2026-11-08)
7
+
8
+ * feat(core)!: an automation or outbound translation hears that its command was refused ([8c9b4b6](https://github.com/ReventlessDev/reventless-core/commit/8c9b4b6c643a5a9e95c85f823fbc333638224346))
9
+ ### Features
10
+
11
+ * **aws:** an automation on AWS hears its command's outcome from the DCB command Lambda ([c9e7edf](https://github.com/ReventlessDev/reventless-core/commit/c9e7edf1c4906238d3a499403335b56f34f6cfd4))
12
+ * **core:** an inbound caller hears the target's refusal, and an unheard refusal is a warning ([3ed23f9](https://github.com/ReventlessDev/reventless-core/commit/3ed23f963fd3abf79d573aa6b0722cfd3e028a74))
13
+
14
+ ### BREAKING CHANGES
15
+
16
+ * an AutomationSlice Automation module written outside an
17
+ @@reventless.automation file must declare onExhausted with ~lastError. External
18
+ consumers need the republished reventless-ppx for the injection.
19
+
20
+
21
+
6
22
  # 3.0.0-alpha.334 (2026-11-08)
7
23
 
8
24
  ### Bug Fixes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reventlessdev/reventless-core",
3
- "version": "3.0.0-alpha.334",
3
+ "version": "3.0.0-alpha.335",
4
4
  "description": "Core package for Reventless framework",
5
5
  "license": "Apache-2.0",
6
6
  "jest": {
@@ -30,15 +30,15 @@
30
30
  "uuid": "^13.0.0",
31
31
  "@reventlessdev/rescript-effect": "1.0.0-alpha.3",
32
32
  "@reventlessdev/rescript-fast-csv": "2.0.0-alpha.26",
33
- "@reventlessdev/rescript-hash-object": "1.2.0-alpha.15",
34
33
  "@reventlessdev/rescript-jest": "1.0.0-alpha.13",
35
34
  "@reventlessdev/rescript-node": "2.0.0-alpha.26",
35
+ "@reventlessdev/rescript-hash-object": "1.2.0-alpha.15",
36
36
  "@reventlessdev/rescript-pulumi-pulumi": "3.0.0-alpha.0",
37
37
  "@reventlessdev/rescript-ssh2": "2.0.0-alpha.27",
38
38
  "@reventlessdev/rescript-uuid": "2.0.0-alpha.1",
39
- "@reventlessdev/reventless-infra": "3.0.0-alpha.227",
40
39
  "@reventlessdev/reventless-interop": "3.0.0-alpha.43",
41
- "@reventlessdev/reventless-spec": "3.0.0-alpha.196"
40
+ "@reventlessdev/reventless-spec": "3.0.0-alpha.197",
41
+ "@reventlessdev/reventless-infra": "3.0.0-alpha.228"
42
42
  },
43
43
  "devDependencies": {
44
44
  "rescript": "12.3.1",
@@ -20,3 +20,13 @@ let announcing = (
20
20
  cmdJsons->Array.forEach(cmdJson => log(~comp, cmdJson))
21
21
  publishJsons(cmdJsons)
22
22
  }
23
+
24
+ /** `announcing` for the publish that waits for each command's outcome. */
25
+ let announcingAndWaiting = (
26
+ ~comp: string,
27
+ publishJsonsAndWait: CommandTopic_Helpers.publishJsonsAndWait,
28
+ ): CommandTopic_Helpers.publishJsonsAndWait =>
29
+ cmdJsons => {
30
+ cmdJsons->Array.forEach(cmdJson => log(~comp, cmdJson))
31
+ publishJsonsAndWait(cmdJsons)
32
+ }
@@ -15,8 +15,16 @@ function announcing(comp, publishJsons) {
15
15
  };
16
16
  }
17
17
 
18
+ function announcingAndWaiting(comp, publishJsonsAndWait) {
19
+ return cmdJsons => {
20
+ cmdJsons.forEach(cmdJson => log(comp, cmdJson));
21
+ return publishJsonsAndWait(cmdJsons);
22
+ };
23
+ }
24
+
18
25
  export {
19
26
  log,
20
27
  announcing,
28
+ announcingAndWaiting,
21
29
  }
22
30
  /* Effect Not a pure module */
@@ -468,6 +468,7 @@ module Make = (
468
468
  CommandTopic_Helpers.reportRejected(
469
469
  ~component=Spec.name,
470
470
  ~correlationId=meta.correlationId,
471
+ ~claimed=meta.callerClaim->Option.isSome,
471
472
  ~causationId=?causedBy,
472
473
  ~cause=DomainRejection,
473
474
  reference,
@@ -478,6 +479,7 @@ module Make = (
478
479
  CommandTopic_Helpers.reportRejected(
479
480
  ~component=Spec.name,
480
481
  ~correlationId=meta.correlationId,
482
+ ~claimed=meta.callerClaim->Option.isSome,
481
483
  ~causationId=?causedBy,
482
484
  ~cause=AccessRefusal,
483
485
  reference,
@@ -507,6 +509,7 @@ module Make = (
507
509
  CommandTopic_Helpers.reportRejected(
508
510
  ~component=Spec.name,
509
511
  ~correlationId=meta.correlationId,
512
+ ~claimed=meta.callerClaim->Option.isSome,
510
513
  ~causationId=?causedBy,
511
514
  ~cause=InfrastructureFailure,
512
515
  reference,
@@ -324,7 +324,7 @@ function Make(Spec) {
324
324
  _0: reference
325
325
  };
326
326
  } else {
327
- CommandTopic_Helpers$ReventlessCore.reportRejected(Spec.name, "InfrastructureFailure", meta.correlationId, causedBy, reference, {
327
+ CommandTopic_Helpers$ReventlessCore.reportRejected(Spec.name, "InfrastructureFailure", meta.correlationId, causedBy, Stdlib_Option.isSome(meta.callerClaim), reference, {
328
328
  errorCode: CommandOutcome$Reventless.code("AppendFailed"),
329
329
  errorDetail: appendErrorDetail
330
330
  });
@@ -334,7 +334,7 @@ function Make(Spec) {
334
334
  };
335
335
  }
336
336
  case "CmdRejected" :
337
- CommandTopic_Helpers$ReventlessCore.reportRejected(Spec.name, "DomainRejection", meta.correlationId, causedBy, reference, {
337
+ CommandTopic_Helpers$ReventlessCore.reportRejected(Spec.name, "DomainRejection", meta.correlationId, causedBy, Stdlib_Option.isSome(meta.callerClaim), reference, {
338
338
  errorCode: outcome.errorCode,
339
339
  errorDetail: outcome.errorDetail
340
340
  });
@@ -343,7 +343,7 @@ function Make(Spec) {
343
343
  _0: reference
344
344
  };
345
345
  case "CmdRefused" :
346
- CommandTopic_Helpers$ReventlessCore.reportRejected(Spec.name, "AccessRefusal", meta.correlationId, causedBy, reference, outcome._0.rejected);
346
+ CommandTopic_Helpers$ReventlessCore.reportRejected(Spec.name, "AccessRefusal", meta.correlationId, causedBy, Stdlib_Option.isSome(meta.callerClaim), reference, outcome._0.rejected);
347
347
  return {
348
348
  TAG: "Ok",
349
349
  _0: reference
@@ -35,6 +35,9 @@ module type T = {
35
35
  let make: (
36
36
  ~allEventTopics: EventTopic.allOutputs,
37
37
  ~publishJsons: Pulumi.Output.t<CommandTopic.publishJsons>,
38
+ /** The target's publish that waits for each command's outcome, where its topic
39
+ offers one; a refusal is then recorded on the row at once. */
40
+ ~publishJsonsAndWait: Pulumi.Output.t<option<CommandTopic.publishJsonsAndWait>>=?,
38
41
  ~context: Reventless.AutomationSlice.context,
39
42
  ~runtime: ReventlessInfra.RuntimeHints.t=?,
40
43
  ~opts: Pulumi.ComponentResource.options=?,
@@ -144,6 +144,7 @@ module Make = (
144
144
  let construct = (
145
145
  ~allEventTopics: EventTopic.allOutputs,
146
146
  ~publishJsons,
147
+ ~publishJsonsAndWait: Pulumi.Output.t<option<CommandTopic.publishJsonsAndWait>>,
147
148
  ~context: Reventless.AutomationSlice.context,
148
149
  ~runtime,
149
150
  self,
@@ -216,9 +217,9 @@ module Make = (
216
217
  // first event arrival (which silently dropped Phase 2 in the previous
217
218
  // shape).
218
219
  let eventCollector =
219
- (queryDb->Component.operations, publishJsons, schedulesOps)
220
- ->Pulumi.Output.all3
221
- ->Pulumi.Output.apply(((queryDbOps, publishJsonsFn, schedulesOps)) => {
220
+ (queryDb->Component.operations, publishJsons, schedulesOps, publishJsonsAndWait)
221
+ ->Pulumi.Output.all4
222
+ ->Pulumi.Output.apply(((queryDbOps, publishJsonsFn, schedulesOps, publishJsonsAndWait)) => {
222
223
  let ec = SpecificEventCollector.make(
223
224
  ~name=Spec.name,
224
225
  ~eventTopics,
@@ -253,7 +254,7 @@ module Make = (
253
254
  // fire-and-forget shape LocalBus already uses for
254
255
  // cross-plugin EP→Extension routing.
255
256
  let _ =
256
- Callback.phase2(publishJsonsFn)
257
+ Callback.phase2(publishJsonsFn, ~publishJsonsAndWait?)
257
258
  ->Promise.then(() => syncToQueryDb(queryDbOps))
258
259
  ->Promise.catch(
259
260
  exn => {
@@ -291,11 +292,18 @@ module Make = (
291
292
  publishJsons,
292
293
  queryDb->Component.operations,
293
294
  schedulesOps,
295
+ publishJsonsAndWait,
294
296
  )
295
- ->Pulumi.Output.all4
296
- ->Pulumi.Output.apply(((ecOps, publishJsonsFn, queryDbOps, schedulesOps)) => {
297
+ ->Pulumi.Output.all5
298
+ ->Pulumi.Output.apply(((
299
+ ecOps,
300
+ publishJsonsFn,
301
+ queryDbOps,
302
+ schedulesOps,
303
+ publishJsonsAndWait,
304
+ )) => {
297
305
  let processPending = async () => {
298
- await Callback.phase2(publishJsonsFn)
306
+ await Callback.phase2(publishJsonsFn, ~publishJsonsAndWait?)
299
307
  await syncToQueryDb(queryDbOps)
300
308
  }
301
309
  let reconcileSchedules = async () =>
@@ -351,6 +359,7 @@ module Make = (
351
359
  let make = (
352
360
  ~allEventTopics,
353
361
  ~publishJsons,
362
+ ~publishJsonsAndWait=Pulumi.Output.make(None),
354
363
  ~context,
355
364
  ~runtime=?,
356
365
  ~opts=?,
@@ -358,7 +367,14 @@ module Make = (
358
367
  Component.make(
359
368
  ~componentType=AutomationSlice.componentType->ComponentType.toString,
360
369
  ~name=Spec.name,
361
- ~construct=construct(~allEventTopics, ~publishJsons, ~context, ~runtime, ...),
370
+ ~construct=construct(
371
+ ~allEventTopics,
372
+ ~publishJsons,
373
+ ~publishJsonsAndWait,
374
+ ~context,
375
+ ~runtime,
376
+ ...
377
+ ),
362
378
  ~opts,
363
379
  )
364
380
  }
@@ -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) => Component$ReventlessCore.make(ComponentType$ReventlessCore.toString(AutomationSlice$ReventlessCore.componentType), Spec.name, (extra, extra$1) => {
91
- let opts_parent = Component$ReventlessCore.toPulumiResource(extra);
92
- let opts = {
93
- parent: opts_parent
94
- };
95
- let memorySize = RuntimeHints$ReventlessInfra.resolveMemory(runtime, 1024);
96
- let timeout = RuntimeHints$ReventlessInfra.resolveTimeout(runtime, 30);
97
- let queryDb = SpecificQueryDb.make(Api.api(), Api.apiRole(), undefined, {
98
- kind: "AutomationSlice",
99
- name: Spec.name
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
- let jsonEventsHandler = stream => Effect$1.flatMap(Stream.runCollect(stream), jsons => Effect$1.promise(async () => {
135
- await Callback.phase1(jsons, context, Capabilities.capabilities());
136
- await syncToQueryDb(queryDbOps);
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
- return {
173
- enqueueEvent: param[0].enqueueEvent,
174
- processPending: processPending,
175
- tick: async (key, at) => {
176
- await Callback.phase1([AutomationSlice_Callback$ReventlessCore.tickEvent(key, at)], context, Capabilities.capabilities());
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
- await syncSchedules(schedulesOps, storedSchedules);
179
- await AutomationSlice_Schedules$ReventlessCore.tell(platform, Callback.takeScheduleChanges());
180
- return await processPending();
181
- },
182
- reconcileSchedules: reconcileSchedules,
183
- rebuildSchedules: async events => {
184
- Callback.rebuildSchedules(events);
185
- return await reconcileSchedules();
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
- let aggregatedResources = Object.values(eventTopics).flatMap(t => t.resources);
190
- let outputs_queryDb = Component$ReventlessCore.outputs(queryDb);
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
- type phase2 = ReventlessInfra.CommandTopic.publishJsons => promise<unit>
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
- {...row, status: retryCount >= Spec.maxRetries ? Abandoned : Failed, retryCount}
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(((targetId, command)) =>
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 (publishJsons: ReventlessInfra.CommandTopic.publishJsons) => {
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
- let _ = commands->Array.push(msg)
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 await publishJsons(commands) catch {
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")