@effect/cluster 0.48.11 → 0.48.13
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/dist/cjs/ClusterCron.js +18 -16
- package/dist/cjs/ClusterCron.js.map +1 -1
- package/dist/cjs/ClusterWorkflowEngine.js +30 -10
- package/dist/cjs/ClusterWorkflowEngine.js.map +1 -1
- package/dist/cjs/Sharding.js +1 -1
- package/dist/cjs/Sharding.js.map +1 -1
- package/dist/dts/ClusterCron.d.ts.map +1 -1
- package/dist/dts/ClusterWorkflowEngine.d.ts.map +1 -1
- package/dist/esm/ClusterCron.js +18 -16
- package/dist/esm/ClusterCron.js.map +1 -1
- package/dist/esm/ClusterWorkflowEngine.js +30 -10
- package/dist/esm/ClusterWorkflowEngine.js.map +1 -1
- package/dist/esm/Sharding.js +1 -1
- package/dist/esm/Sharding.js.map +1 -1
- package/package.json +2 -2
- package/src/ClusterCron.ts +8 -5
- package/src/ClusterWorkflowEngine.ts +58 -20
- package/src/Sharding.ts +1 -1
|
@@ -70,6 +70,19 @@ export const make = Effect.gen(function*() {
|
|
|
70
70
|
| Rpc.Rpc<"resume">
|
|
71
71
|
>
|
|
72
72
|
>()
|
|
73
|
+
const partialEntities = new Map<
|
|
74
|
+
string,
|
|
75
|
+
Entity.Entity<
|
|
76
|
+
string,
|
|
77
|
+
| Rpc.Rpc<"deferred", Schema.Struct<{ name: typeof Schema.String; exit: typeof ExitUnknown }>, typeof ExitUnknown>
|
|
78
|
+
| Rpc.Rpc<
|
|
79
|
+
"activity",
|
|
80
|
+
Schema.Struct<{ name: typeof Schema.String; attempt: typeof Schema.Number }>,
|
|
81
|
+
Schema.Schema<Workflow.Result<any, any>>
|
|
82
|
+
>
|
|
83
|
+
| Rpc.Rpc<"resume">
|
|
84
|
+
>
|
|
85
|
+
>()
|
|
73
86
|
const ensureEntity = (workflow: Workflow.Any) => {
|
|
74
87
|
let entity = entities.get(workflow.name)
|
|
75
88
|
if (!entity) {
|
|
@@ -79,6 +92,14 @@ export const make = Effect.gen(function*() {
|
|
|
79
92
|
}
|
|
80
93
|
return entity!
|
|
81
94
|
}
|
|
95
|
+
const ensurePartialEntity = (workflowName: string) => {
|
|
96
|
+
let entity = partialEntities.get(workflowName)
|
|
97
|
+
if (!entity) {
|
|
98
|
+
entity = makePartialWorkflowEntity(workflowName) as any
|
|
99
|
+
partialEntities.set(workflowName, entity as any)
|
|
100
|
+
}
|
|
101
|
+
return entity!
|
|
102
|
+
}
|
|
82
103
|
|
|
83
104
|
const activities = new Map<string, {
|
|
84
105
|
readonly activity: Activity.Any
|
|
@@ -95,6 +116,13 @@ export const make = Effect.gen(function*() {
|
|
|
95
116
|
}),
|
|
96
117
|
idleTimeToLive: "5 minutes"
|
|
97
118
|
})
|
|
119
|
+
const clientsPartial = yield* RcMap.make({
|
|
120
|
+
lookup: Effect.fnUntraced(function*(workflowName: string) {
|
|
121
|
+
const entity = entities.get(workflowName) ?? ensurePartialEntity(workflowName)
|
|
122
|
+
return yield* entity.client
|
|
123
|
+
}),
|
|
124
|
+
idleTimeToLive: "5 minutes"
|
|
125
|
+
})
|
|
98
126
|
const clockClient = yield* ClockEntity.client
|
|
99
127
|
|
|
100
128
|
const requestIdFor = Effect.fnUntraced(function*(options: {
|
|
@@ -211,7 +239,7 @@ export const make = Effect.gen(function*() {
|
|
|
211
239
|
readonly workflowName: string
|
|
212
240
|
readonly executionId: string
|
|
213
241
|
}) {
|
|
214
|
-
const client = (yield* RcMap.get(
|
|
242
|
+
const client = (yield* RcMap.get(clientsPartial, options.workflowName))(options.executionId)
|
|
215
243
|
return yield* client.resume(void 0, { discard: true })
|
|
216
244
|
}, Effect.scoped)
|
|
217
245
|
|
|
@@ -342,6 +370,7 @@ export const make = Effect.gen(function*() {
|
|
|
342
370
|
|
|
343
371
|
interrupt: Effect.fnUntraced(
|
|
344
372
|
function*(this: WorkflowEngine["Type"], workflow, executionId) {
|
|
373
|
+
ensureEntity(workflow)
|
|
345
374
|
const reply = yield* requestReply({
|
|
346
375
|
workflow,
|
|
347
376
|
entityType: `Workflow/${workflow.name}`,
|
|
@@ -403,7 +432,7 @@ export const make = Effect.gen(function*() {
|
|
|
403
432
|
yield* latch.release
|
|
404
433
|
activityLatches.delete(activityId)
|
|
405
434
|
}
|
|
406
|
-
const client = (yield* RcMap.get(
|
|
435
|
+
const client = (yield* RcMap.get(clientsPartial, instance.workflow.name))(instance.executionId)
|
|
407
436
|
while (true) {
|
|
408
437
|
const result = yield* Effect.orDie(client.activity({ name: activity.name, attempt }))
|
|
409
438
|
// If the activity has suspended and did not execute, we need to resume
|
|
@@ -465,7 +494,7 @@ export const make = Effect.gen(function*() {
|
|
|
465
494
|
|
|
466
495
|
deferredDone: Effect.fnUntraced(
|
|
467
496
|
function*({ deferredName, executionId, exit, workflowName }) {
|
|
468
|
-
const client = yield* RcMap.get(
|
|
497
|
+
const client = yield* RcMap.get(clientsPartial, workflowName)
|
|
469
498
|
return yield* Effect.orDie(
|
|
470
499
|
client(executionId).deferred({
|
|
471
500
|
name: deferredName,
|
|
@@ -544,32 +573,41 @@ const makeWorkflowEntity = (workflow: Workflow.Any) =>
|
|
|
544
573
|
.annotate(ClusterSchema.Persisted, true)
|
|
545
574
|
.annotate(ClusterSchema.Uninterruptible, true),
|
|
546
575
|
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
name: Schema.String,
|
|
550
|
-
exit: ExitUnknown
|
|
551
|
-
},
|
|
552
|
-
primaryKey: ({ name }) => name,
|
|
553
|
-
success: ExitUnknown
|
|
554
|
-
})
|
|
555
|
-
.annotate(ClusterSchema.Persisted, true)
|
|
556
|
-
.annotate(ClusterSchema.Uninterruptible, true),
|
|
557
|
-
|
|
558
|
-
Rpc.make("resume")
|
|
559
|
-
.annotate(ClusterSchema.Persisted, true)
|
|
560
|
-
.annotate(ClusterSchema.Uninterruptible, true),
|
|
561
|
-
|
|
576
|
+
DeferredRpc,
|
|
577
|
+
ResumeRpc,
|
|
562
578
|
ActivityRpc
|
|
563
579
|
]).annotateContext(workflow.annotations)
|
|
564
580
|
|
|
565
|
-
const activityPrimaryKey = (activity: string, attempt: number) => `${activity}/${attempt}`
|
|
566
|
-
|
|
567
581
|
const ExitUnknown = Schema.encodedSchema(Schema.Exit({
|
|
568
582
|
success: Schema.Unknown,
|
|
569
583
|
failure: Schema.Unknown,
|
|
570
584
|
defect: Schema.Defect
|
|
571
585
|
}))
|
|
572
586
|
|
|
587
|
+
const DeferredRpc = Rpc.make("deferred", {
|
|
588
|
+
payload: {
|
|
589
|
+
name: Schema.String,
|
|
590
|
+
exit: ExitUnknown
|
|
591
|
+
},
|
|
592
|
+
primaryKey: ({ name }) => name,
|
|
593
|
+
success: ExitUnknown
|
|
594
|
+
})
|
|
595
|
+
.annotate(ClusterSchema.Persisted, true)
|
|
596
|
+
.annotate(ClusterSchema.Uninterruptible, true)
|
|
597
|
+
|
|
598
|
+
const ResumeRpc = Rpc.make("resume")
|
|
599
|
+
.annotate(ClusterSchema.Persisted, true)
|
|
600
|
+
.annotate(ClusterSchema.Uninterruptible, true)
|
|
601
|
+
|
|
602
|
+
const makePartialWorkflowEntity = (workflowName: string) =>
|
|
603
|
+
Entity.make(`Workflow/${workflowName}`, [
|
|
604
|
+
DeferredRpc,
|
|
605
|
+
ResumeRpc,
|
|
606
|
+
ActivityRpc
|
|
607
|
+
])
|
|
608
|
+
|
|
609
|
+
const activityPrimaryKey = (activity: string, attempt: number) => `${activity}/${attempt}`
|
|
610
|
+
|
|
573
611
|
class ClockPayload extends Schema.Class<ClockPayload>(`Workflow/DurableClock/Run`)({
|
|
574
612
|
name: Schema.String,
|
|
575
613
|
workflowName: Schema.String,
|
package/src/Sharding.ts
CHANGED
|
@@ -821,7 +821,7 @@ const make = Effect.gen(function*() {
|
|
|
821
821
|
// and re-subscribe to sharding events
|
|
822
822
|
yield* Effect.gen(function*() {
|
|
823
823
|
yield* Effect.logDebug("Registering with shard manager")
|
|
824
|
-
if (Option.isSome(config.runnerAddress)) {
|
|
824
|
+
if (!isShutdown.current && Option.isSome(config.runnerAddress)) {
|
|
825
825
|
const machineId = yield* shardManager.register(config.runnerAddress.value, config.shardGroups)
|
|
826
826
|
yield* snowflakeGen.setMachineId(machineId)
|
|
827
827
|
}
|