effect 4.1.5 → 4.1.6
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/ai-docs/package.json +2 -2
- package/dist/Channel.d.ts +104 -7
- package/dist/Channel.d.ts.map +1 -1
- package/dist/Channel.js +73 -4
- package/dist/Channel.js.map +1 -1
- package/dist/Codegen.d.ts +7 -2
- package/dist/Codegen.d.ts.map +1 -1
- package/dist/Codegen.js +7 -2
- package/dist/Codegen.js.map +1 -1
- package/dist/Effect.d.ts +139 -18
- package/dist/Effect.d.ts.map +1 -1
- package/dist/Effect.js +10 -2
- package/dist/Effect.js.map +1 -1
- package/dist/Equal.d.ts +4 -4
- package/dist/Equal.d.ts.map +1 -1
- package/dist/Equal.js +78 -65
- package/dist/Equal.js.map +1 -1
- package/dist/Hash.d.ts.map +1 -1
- package/dist/Hash.js +24 -17
- package/dist/Hash.js.map +1 -1
- package/dist/LayerRef.d.ts +1 -1
- package/dist/LayerRef.d.ts.map +1 -1
- package/dist/LayerRef.js +3 -3
- package/dist/LayerRef.js.map +1 -1
- package/dist/Logger.d.ts +37 -13
- package/dist/Logger.d.ts.map +1 -1
- package/dist/Logger.js +39 -10
- package/dist/Logger.js.map +1 -1
- package/dist/Match.d.ts +23 -23
- package/dist/Match.d.ts.map +1 -1
- package/dist/Match.js.map +1 -1
- package/dist/Order.js +1 -1
- package/dist/Order.js.map +1 -1
- package/dist/Schema.d.ts +41 -0
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +51 -390
- package/dist/Schema.js.map +1 -1
- package/dist/SchemaAST.d.ts.map +1 -1
- package/dist/SchemaAST.js +0 -3
- package/dist/SchemaAST.js.map +1 -1
- package/dist/ScopedCache.d.ts.map +1 -1
- package/dist/ScopedCache.js +6 -4
- package/dist/ScopedCache.js.map +1 -1
- package/dist/Stream.d.ts +128 -5
- package/dist/Stream.d.ts.map +1 -1
- package/dist/Stream.js +124 -29
- package/dist/Stream.js.map +1 -1
- package/dist/String.js +1 -1
- package/dist/String.js.map +1 -1
- package/dist/Tracer.d.ts +10 -0
- package/dist/Tracer.d.ts.map +1 -1
- package/dist/Tracer.js +2 -0
- package/dist/Tracer.js.map +1 -1
- package/dist/ai/McpSchema.d.ts +88 -88
- package/dist/ai/McpSchema.d.ts.map +1 -1
- package/dist/ai/McpServer.d.ts +152 -2
- package/dist/ai/McpServer.d.ts.map +1 -1
- package/dist/ai/McpServer.js +8 -2
- package/dist/ai/McpServer.js.map +1 -1
- package/dist/ai/Prompt.d.ts +3 -1
- package/dist/ai/Prompt.d.ts.map +1 -1
- package/dist/ai/Prompt.js +17 -3
- package/dist/ai/Prompt.js.map +1 -1
- package/dist/ai/Skill.d.ts +172 -0
- package/dist/ai/Skill.d.ts.map +1 -0
- package/dist/ai/Skill.js +209 -0
- package/dist/ai/Skill.js.map +1 -0
- package/dist/ai/index.d.ts +5 -0
- package/dist/ai/index.d.ts.map +1 -1
- package/dist/ai/index.js +5 -0
- package/dist/ai/index.js.map +1 -1
- package/dist/cluster/ClusterWorkflowEngine.d.ts.map +1 -1
- package/dist/cluster/ClusterWorkflowEngine.js +155 -83
- package/dist/cluster/ClusterWorkflowEngine.js.map +1 -1
- package/dist/cluster/MessageStorage.d.ts +56 -0
- package/dist/cluster/MessageStorage.d.ts.map +1 -1
- package/dist/cluster/MessageStorage.js +18 -2
- package/dist/cluster/MessageStorage.js.map +1 -1
- package/dist/cluster/SqlMessageStorage.d.ts.map +1 -1
- package/dist/cluster/SqlMessageStorage.js +45 -22
- package/dist/cluster/SqlMessageStorage.js.map +1 -1
- package/dist/cluster/internal/entityActivation.js +2 -0
- package/dist/cluster/internal/entityActivation.js.map +1 -1
- package/dist/cluster/internal/entityManager.js +8 -5
- package/dist/cluster/internal/entityManager.js.map +1 -1
- package/dist/encoding/Base64.js +5 -1
- package/dist/encoding/Base64.js.map +1 -1
- package/dist/encoding/Base64Url.d.ts.map +1 -1
- package/dist/encoding/Base64Url.js +6 -1
- package/dist/encoding/Base64Url.js.map +1 -1
- package/dist/encoding/Xml.d.ts +38 -9
- package/dist/encoding/Xml.d.ts.map +1 -1
- package/dist/encoding/Xml.js +63 -31
- package/dist/encoding/Xml.js.map +1 -1
- package/dist/http/FetchHttpClient.d.ts +2 -1
- package/dist/http/FetchHttpClient.d.ts.map +1 -1
- package/dist/http/FetchHttpClient.js +14 -10
- package/dist/http/FetchHttpClient.js.map +1 -1
- package/dist/http/Headers.d.ts +201 -3
- package/dist/http/Headers.d.ts.map +1 -1
- package/dist/http/Headers.js +205 -3
- package/dist/http/Headers.js.map +1 -1
- package/dist/http/HttpClient.d.ts.map +1 -1
- package/dist/http/HttpClient.js +11 -7
- package/dist/http/HttpClient.js.map +1 -1
- package/dist/http/HttpClientError.d.ts +1 -0
- package/dist/http/HttpClientError.d.ts.map +1 -1
- package/dist/http/HttpClientError.js +32 -9
- package/dist/http/HttpClientError.js.map +1 -1
- package/dist/http/HttpClientRequest.d.ts +46 -0
- package/dist/http/HttpClientRequest.d.ts.map +1 -1
- package/dist/http/HttpClientRequest.js +15 -0
- package/dist/http/HttpClientRequest.js.map +1 -1
- package/dist/http/HttpClientResponse.d.ts +132 -0
- package/dist/http/HttpClientResponse.d.ts.map +1 -1
- package/dist/http/HttpClientResponse.js +83 -0
- package/dist/http/HttpClientResponse.js.map +1 -1
- package/dist/http/HttpMiddleware.js +1 -1
- package/dist/http/HttpMiddleware.js.map +1 -1
- package/dist/http/HttpServerResponse.d.ts +118 -0
- package/dist/http/HttpServerResponse.d.ts.map +1 -1
- package/dist/http/HttpServerResponse.js +43 -0
- package/dist/http/HttpServerResponse.js.map +1 -1
- package/dist/http/Multipart.d.ts.map +1 -1
- package/dist/http/Multipart.js +0 -5
- package/dist/http/Multipart.js.map +1 -1
- package/dist/http/MultipartParser/internal/contentType.d.ts +6 -0
- package/dist/http/MultipartParser/internal/contentType.d.ts.map +1 -1
- package/dist/http/MultipartParser/internal/contentType.js +1 -1
- package/dist/http/MultipartParser/internal/contentType.js.map +1 -1
- package/dist/http/internal/clientPath.d.ts +2 -0
- package/dist/http/internal/clientPath.d.ts.map +1 -0
- package/dist/http/internal/clientPath.js +24 -0
- package/dist/http/internal/clientPath.js.map +1 -0
- package/dist/http/internal/redactedPath.js +2 -0
- package/dist/http/internal/redactedPath.js.map +1 -1
- package/dist/http/internal/tracing.js +5 -3
- package/dist/http/internal/tracing.js.map +1 -1
- package/dist/http-api/HttpApi.d.ts +2 -2
- package/dist/http-api/HttpApi.d.ts.map +1 -1
- package/dist/http-api/HttpApi.js +30 -7
- package/dist/http-api/HttpApi.js.map +1 -1
- package/dist/http-api/HttpApiBuilder.d.ts.map +1 -1
- package/dist/http-api/HttpApiBuilder.js +5 -2
- package/dist/http-api/HttpApiBuilder.js.map +1 -1
- package/dist/http-api/HttpApiClient.d.ts.map +1 -1
- package/dist/http-api/HttpApiClient.js +23 -6
- package/dist/http-api/HttpApiClient.js.map +1 -1
- package/dist/http-api/internal/redactedKeys.d.ts +2 -0
- package/dist/http-api/internal/redactedKeys.d.ts.map +1 -0
- package/dist/http-api/internal/redactedKeys.js +37 -0
- package/dist/http-api/internal/redactedKeys.js.map +1 -0
- package/dist/internal/base64.js +34 -2
- package/dist/internal/base64.js.map +1 -1
- package/dist/internal/dateTime.js +35 -17
- package/dist/internal/dateTime.js.map +1 -1
- package/dist/internal/effect.js +9 -1
- package/dist/internal/effect.js.map +1 -1
- package/dist/internal/equal.js +14 -13
- package/dist/internal/equal.js.map +1 -1
- package/dist/internal/hash.js +4 -1
- package/dist/internal/hash.js.map +1 -1
- package/dist/internal/matcher.js +17 -17
- package/dist/internal/matcher.js.map +1 -1
- package/dist/internal/schema/schemaCodegen.js +3 -2
- package/dist/internal/schema/schemaCodegen.js.map +1 -1
- package/dist/internal/schema/schemaCodegenBuiltIns.d.ts +2 -0
- package/dist/internal/schema/schemaCodegenBuiltIns.d.ts.map +1 -0
- package/dist/internal/schema/schemaCodegenBuiltIns.js +425 -0
- package/dist/internal/schema/schemaCodegenBuiltIns.js.map +1 -0
- package/dist/internal/schema/toEquivalence.js +3 -4
- package/dist/internal/schema/toEquivalence.js.map +1 -1
- package/dist/internal/version.js +1 -1
- package/dist/jose/JoseError.d.ts +51 -1
- package/dist/jose/JoseError.d.ts.map +1 -1
- package/dist/jose/JoseError.js +25 -18
- package/dist/jose/JoseError.js.map +1 -1
- package/dist/jose/internal/compact.js +10 -5
- package/dist/jose/internal/compact.js.map +1 -1
- package/dist/observability/Otlp.d.ts +19 -0
- package/dist/observability/Otlp.d.ts.map +1 -1
- package/dist/observability/Otlp.js +10 -0
- package/dist/observability/Otlp.js.map +1 -1
- package/dist/observability/OtlpExporter.d.ts +49 -13
- package/dist/observability/OtlpExporter.d.ts.map +1 -1
- package/dist/observability/OtlpExporter.js +135 -54
- package/dist/observability/OtlpExporter.js.map +1 -1
- package/dist/observability/OtlpLogger.d.ts +14 -0
- package/dist/observability/OtlpLogger.d.ts.map +1 -1
- package/dist/observability/OtlpLogger.js +10 -2
- package/dist/observability/OtlpLogger.js.map +1 -1
- package/dist/observability/OtlpMetrics.d.ts.map +1 -1
- package/dist/observability/OtlpMetrics.js +2 -0
- package/dist/observability/OtlpMetrics.js.map +1 -1
- package/dist/observability/OtlpTracer.d.ts +14 -0
- package/dist/observability/OtlpTracer.d.ts.map +1 -1
- package/dist/observability/OtlpTracer.js +10 -2
- package/dist/observability/OtlpTracer.js.map +1 -1
- package/dist/persistence/KeyValueStore.d.ts.map +1 -1
- package/dist/persistence/KeyValueStore.js +6 -4
- package/dist/persistence/KeyValueStore.js.map +1 -1
- package/dist/reactivity/Atom.d.ts.map +1 -1
- package/dist/reactivity/Atom.js +10 -9
- package/dist/reactivity/Atom.js.map +1 -1
- package/dist/rpc/RpcClient.d.ts.map +1 -1
- package/dist/rpc/RpcClient.js +32 -1
- package/dist/rpc/RpcClient.js.map +1 -1
- package/dist/rpc/RpcGroup.d.ts +1 -1
- package/dist/rpc/RpcGroup.d.ts.map +1 -1
- package/dist/rpc/RpcGroup.js +4 -0
- package/dist/rpc/RpcGroup.js.map +1 -1
- package/dist/sql/Migrator.d.ts.map +1 -1
- package/dist/sql/Migrator.js +2 -5
- package/dist/sql/Migrator.js.map +1 -1
- package/dist/sql/SqlClient.d.ts.map +1 -1
- package/dist/sql/SqlClient.js +5 -1
- package/dist/sql/SqlClient.js.map +1 -1
- package/dist/workflow/Activity.d.ts +18 -0
- package/dist/workflow/Activity.d.ts.map +1 -1
- package/dist/workflow/Activity.js +13 -4
- package/dist/workflow/Activity.js.map +1 -1
- package/dist/workflow/Workflow.d.ts +10 -9
- package/dist/workflow/Workflow.d.ts.map +1 -1
- package/dist/workflow/Workflow.js +33 -22
- package/dist/workflow/Workflow.js.map +1 -1
- package/dist/workflow/WorkflowEngine.d.ts.map +1 -1
- package/dist/workflow/WorkflowEngine.js +26 -12
- package/dist/workflow/WorkflowEngine.js.map +1 -1
- package/dist/workflow/internal/retry.d.ts +2 -0
- package/dist/workflow/internal/retry.d.ts.map +1 -0
- package/dist/workflow/internal/retry.js +11 -0
- package/dist/workflow/internal/retry.js.map +1 -0
- package/dist/workflow/internal/scope.d.ts +2 -0
- package/dist/workflow/internal/scope.d.ts.map +1 -0
- package/dist/workflow/internal/scope.js +26 -0
- package/dist/workflow/internal/scope.js.map +1 -0
- package/package.json +3 -3
- package/src/Channel.ts +105 -8
- package/src/Codegen.ts +7 -2
- package/src/Effect.ts +224 -48
- package/src/Equal.ts +85 -79
- package/src/Hash.ts +30 -22
- package/src/LayerRef.ts +6 -4
- package/src/Logger.ts +68 -25
- package/src/Match.ts +78 -50
- package/src/Order.ts +1 -1
- package/src/Schema.ts +79 -296
- package/src/SchemaAST.ts +0 -1
- package/src/ScopedCache.ts +6 -4
- package/src/Stream.ts +167 -33
- package/src/String.ts +1 -1
- package/src/Tracer.ts +10 -0
- package/src/ai/McpServer.ts +161 -4
- package/src/ai/Prompt.ts +20 -3
- package/src/ai/Skill.ts +236 -0
- package/src/ai/index.ts +6 -0
- package/src/cluster/ClusterWorkflowEngine.ts +172 -96
- package/src/cluster/MessageStorage.ts +51 -2
- package/src/cluster/SqlMessageStorage.ts +81 -34
- package/src/cluster/internal/entityActivation.ts +6 -0
- package/src/cluster/internal/entityManager.ts +8 -4
- package/src/encoding/Base64.ts +5 -1
- package/src/encoding/Base64Url.ts +6 -1
- package/src/encoding/Xml.ts +96 -26
- package/src/http/FetchHttpClient.ts +8 -5
- package/src/http/Headers.ts +309 -3
- package/src/http/HttpClient.ts +19 -7
- package/src/http/HttpClientError.ts +42 -9
- package/src/http/HttpClientRequest.ts +51 -0
- package/src/http/HttpClientResponse.ts +156 -0
- package/src/http/HttpMiddleware.ts +1 -1
- package/src/http/HttpServerResponse.ts +126 -0
- package/src/http/Multipart.ts +0 -5
- package/src/http/MultipartParser/internal/contentType.ts +1 -1
- package/src/http/internal/clientPath.ts +39 -0
- package/src/http/internal/redactedPath.ts +4 -0
- package/src/http/internal/tracing.ts +6 -3
- package/src/http-api/HttpApi.ts +29 -8
- package/src/http-api/HttpApiBuilder.ts +7 -2
- package/src/http-api/HttpApiClient.ts +30 -7
- package/src/http-api/internal/redactedKeys.ts +40 -0
- package/src/internal/base64.ts +57 -2
- package/src/internal/dateTime.ts +43 -24
- package/src/internal/effect.ts +31 -102
- package/src/internal/equal.ts +37 -17
- package/src/internal/hash.ts +5 -1
- package/src/internal/matcher.ts +34 -113
- package/src/internal/schema/schemaCodegen.ts +5 -4
- package/src/internal/schema/schemaCodegenBuiltIns.ts +343 -0
- package/src/internal/schema/toEquivalence.ts +3 -5
- package/src/internal/version.ts +1 -1
- package/src/jose/JoseError.ts +34 -0
- package/src/jose/internal/compact.ts +14 -5
- package/src/observability/Otlp.ts +29 -0
- package/src/observability/OtlpExporter.ts +206 -75
- package/src/observability/OtlpLogger.ts +24 -2
- package/src/observability/OtlpMetrics.ts +2 -0
- package/src/observability/OtlpTracer.ts +24 -3
- package/src/persistence/KeyValueStore.ts +17 -14
- package/src/reactivity/Atom.ts +12 -18
- package/src/rpc/RpcClient.ts +26 -1
- package/src/rpc/RpcGroup.ts +4 -1
- package/src/sql/Migrator.ts +2 -11
- package/src/sql/SqlClient.ts +14 -8
- package/src/workflow/Activity.ts +28 -4
- package/src/workflow/Workflow.ts +68 -44
- package/src/workflow/WorkflowEngine.ts +38 -15
- package/src/workflow/internal/retry.ts +12 -0
- package/src/workflow/internal/scope.ts +36 -0
|
@@ -16,6 +16,7 @@ import * as Effect from "../Effect.ts"
|
|
|
16
16
|
import * as Exit from "../Exit.ts"
|
|
17
17
|
import * as Fiber from "../Fiber.ts"
|
|
18
18
|
import * as Headers from "../http/Headers.ts"
|
|
19
|
+
import * as Latch from "../Latch.ts"
|
|
19
20
|
import * as Layer from "../Layer.ts"
|
|
20
21
|
import * as Option from "../Option.ts"
|
|
21
22
|
import * as PrimaryKey from "../PrimaryKey.ts"
|
|
@@ -30,6 +31,8 @@ import * as Semaphore from "../Semaphore.ts"
|
|
|
30
31
|
import * as Activity from "../workflow/Activity.ts"
|
|
31
32
|
import * as DurableClock from "../workflow/DurableClock.ts"
|
|
32
33
|
import * as DurableDeferred from "../workflow/DurableDeferred.ts"
|
|
34
|
+
import { RetryingExecution } from "../workflow/internal/retry.ts"
|
|
35
|
+
import { markScopeAbandoned, reuseOrForkScope } from "../workflow/internal/scope.ts"
|
|
33
36
|
import * as Workflow from "../workflow/Workflow.ts"
|
|
34
37
|
import * as WorkflowEngine from "../workflow/WorkflowEngine.ts"
|
|
35
38
|
import * as ClusterSchema from "./ClusterSchema.ts"
|
|
@@ -40,7 +43,7 @@ import * as EntityId from "./EntityId.ts"
|
|
|
40
43
|
import * as EntityType from "./EntityType.ts"
|
|
41
44
|
import * as Envelope from "./Envelope.ts"
|
|
42
45
|
import * as ClusterAbandon from "./internal/clusterAbandon.ts"
|
|
43
|
-
import { CurrentActivationScope } from "./internal/entityActivation.ts"
|
|
46
|
+
import { CurrentActivationScope, CurrentRetirementLatch } from "./internal/entityActivation.ts"
|
|
44
47
|
import * as Message from "./Message.ts"
|
|
45
48
|
import { MessageStorage } from "./MessageStorage.ts"
|
|
46
49
|
import type { WithExitEncoded } from "./Reply.ts"
|
|
@@ -94,6 +97,7 @@ export const make = Effect.gen(function*() {
|
|
|
94
97
|
Schema.declare<Workflow.Result<any, any>>
|
|
95
98
|
>
|
|
96
99
|
| typeof ResumeRpc
|
|
100
|
+
| typeof ParentRpc
|
|
97
101
|
>
|
|
98
102
|
>()
|
|
99
103
|
const partialEntities = new Map<
|
|
@@ -106,7 +110,6 @@ export const make = Effect.gen(function*() {
|
|
|
106
110
|
Schema.Struct<{ name: typeof Schema.String; attempt: typeof Schema.Int }>,
|
|
107
111
|
Schema.declare<Workflow.Result<any, any>>
|
|
108
112
|
>
|
|
109
|
-
| typeof ResumeRpc
|
|
110
113
|
>
|
|
111
114
|
>()
|
|
112
115
|
const ensureEntity = (workflow: Workflow.Any) => {
|
|
@@ -142,9 +145,8 @@ export const make = Effect.gen(function*() {
|
|
|
142
145
|
Effect.suspend(() => {
|
|
143
146
|
const scope = state.scope
|
|
144
147
|
if (abandoned) {
|
|
145
|
-
|
|
148
|
+
markScopeAbandoned(scope)
|
|
146
149
|
}
|
|
147
|
-
state.instances.clear()
|
|
148
150
|
state.scope = Scope.makeUnsafe()
|
|
149
151
|
return Scope.close(scope, Exit.void)
|
|
150
152
|
})
|
|
@@ -166,21 +168,21 @@ export const make = Effect.gen(function*() {
|
|
|
166
168
|
}),
|
|
167
169
|
idleTimeToLive: "5 minutes"
|
|
168
170
|
})
|
|
169
|
-
const
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
}) => {
|
|
174
|
-
const shardGroup = Context.get(options.workflow.annotations, ClusterSchema.ShardGroup)(
|
|
175
|
-
options.executionId as EntityId.EntityId
|
|
176
|
-
)
|
|
177
|
-
const entityId = EntityId.make(options.executionId)
|
|
171
|
+
const shardGroupFor = (workflow: Workflow.Any, executionId: string) =>
|
|
172
|
+
Context.get(workflow.annotations, ClusterSchema.ShardGroup)(executionId as EntityId.EntityId)
|
|
173
|
+
const entityAddress = (entityType: string, executionId: string, shardGroup: string) => {
|
|
174
|
+
const entityId = EntityId.make(executionId)
|
|
178
175
|
return EntityAddress.make({
|
|
179
|
-
entityType: EntityType.make(
|
|
176
|
+
entityType: EntityType.make(entityType),
|
|
180
177
|
entityId,
|
|
181
178
|
shardId: sharding.getShardId(entityId, shardGroup)
|
|
182
179
|
})
|
|
183
180
|
}
|
|
181
|
+
const entityAddressFor = (options: {
|
|
182
|
+
readonly workflow: Workflow.Any
|
|
183
|
+
readonly entityType: string
|
|
184
|
+
readonly executionId: string
|
|
185
|
+
}) => entityAddress(options.entityType, options.executionId, shardGroupFor(options.workflow, options.executionId))
|
|
184
186
|
|
|
185
187
|
const sendDiscard = Effect.fnUntraced(function*(options: {
|
|
186
188
|
readonly rpc: Rpc.AnyWithProps
|
|
@@ -249,6 +251,9 @@ export const make = Effect.gen(function*() {
|
|
|
249
251
|
return yield* replyForRequestId(requestId.value)
|
|
250
252
|
})
|
|
251
253
|
|
|
254
|
+
const runReply = (workflow: Workflow.Any, executionId: string) =>
|
|
255
|
+
requestReply({ workflow, entityType: `Workflow/${workflow._tag}`, executionId, tag: "run", id: "" })
|
|
256
|
+
|
|
252
257
|
const resetActivityAttempt = Effect.fnUntraced(
|
|
253
258
|
function*(options: {
|
|
254
259
|
readonly workflow: Workflow.Any
|
|
@@ -281,27 +286,11 @@ export const make = Effect.gen(function*() {
|
|
|
281
286
|
readonly workflow: Workflow.Any
|
|
282
287
|
readonly executionId: string
|
|
283
288
|
}) {
|
|
284
|
-
|
|
285
|
-
options.executionId as EntityId.EntityId
|
|
286
|
-
)
|
|
287
|
-
const entityId = EntityId.make(options.executionId)
|
|
288
|
-
const shardId = sharding.getShardId(entityId, shardGroup)
|
|
289
|
-
const clockAddress = EntityAddress.make({
|
|
290
|
-
entityType: ClockEntity.type,
|
|
291
|
-
entityId,
|
|
292
|
-
shardId
|
|
293
|
-
})
|
|
294
|
-
yield* storage.clearAddress(clockAddress)
|
|
289
|
+
yield* storage.clearAddress(entityAddressFor({ ...options, entityType: ClockEntity.type }))
|
|
295
290
|
})
|
|
296
291
|
|
|
297
292
|
const resume = Effect.fnUntraced(function*(workflow: Workflow.Any, executionId: string, mode: WakeMode) {
|
|
298
|
-
const maybeReply = yield*
|
|
299
|
-
workflow,
|
|
300
|
-
entityType: `Workflow/${workflow._tag}`,
|
|
301
|
-
executionId,
|
|
302
|
-
tag: "run",
|
|
303
|
-
id: ""
|
|
304
|
-
})
|
|
293
|
+
const maybeReply = yield* runReply(workflow, executionId)
|
|
305
294
|
|
|
306
295
|
const maybeSuspended = Option.filter(maybeReply, isSuspendedReply)
|
|
307
296
|
|
|
@@ -328,25 +317,30 @@ export const make = Effect.gen(function*() {
|
|
|
328
317
|
pending.results.has(InterruptSignal.name)
|
|
329
318
|
})
|
|
330
319
|
|
|
331
|
-
const sendResumeParent = Effect.fnUntraced(function*(
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
320
|
+
const sendResumeParent = Effect.fnUntraced(function*(parent: ParentRef, childExecutionId: string) {
|
|
321
|
+
// Parents saved before `shardGroup` existed, or in the default group, omit it.
|
|
322
|
+
const workflow = workflows.get(parent.workflowName)
|
|
323
|
+
const address = entityAddress(
|
|
324
|
+
`Workflow/${parent.workflowName}`,
|
|
325
|
+
parent.executionId,
|
|
326
|
+
parent.shardGroup ?? (workflow ? shardGroupFor(workflow, parent.executionId) : "default")
|
|
327
|
+
)
|
|
328
|
+
const requestId = yield* storage.requestIdForPrimaryKey({
|
|
329
|
+
address,
|
|
339
330
|
tag: "resume",
|
|
340
331
|
id: childExecutionId
|
|
341
332
|
})
|
|
342
333
|
if (Option.isNone(requestId)) {
|
|
343
|
-
|
|
344
|
-
|
|
334
|
+
return yield* sendDiscard({
|
|
335
|
+
rpc: ResumeRpc,
|
|
336
|
+
address,
|
|
337
|
+
payload: { childExecutionId }
|
|
338
|
+
})
|
|
345
339
|
}
|
|
346
340
|
const reply = yield* replyForRequestId(requestId.value)
|
|
347
341
|
if (Option.isNone(reply)) return
|
|
348
342
|
yield* sharding.reset(requestId.value, { expectedReplyId: Snowflake.Snowflake(reply.value.id) })
|
|
349
|
-
}
|
|
343
|
+
})
|
|
350
344
|
|
|
351
345
|
// Subscribe to the run's next reply before reading storage, so a reply
|
|
352
346
|
// cannot fall between the read and the subscription. Returns `true` when the
|
|
@@ -421,11 +415,7 @@ export const make = Effect.gen(function*() {
|
|
|
421
415
|
}
|
|
422
416
|
const reply = yield* replyForRequestId(requestId.value)
|
|
423
417
|
|
|
424
|
-
|
|
425
|
-
reply,
|
|
426
|
-
(reply) => !isSuspendedReply(reply)
|
|
427
|
-
)
|
|
428
|
-
if (Option.isSome(nonSuspendedReply)) {
|
|
418
|
+
if (isRunSettled(reply)) {
|
|
429
419
|
return Option.none()
|
|
430
420
|
}
|
|
431
421
|
|
|
@@ -471,12 +461,15 @@ export const make = Effect.gen(function*() {
|
|
|
471
461
|
(decoded.exit._tag === "Success" ? decoded.exit.value : decoded.exit) as Exit.Exit<unknown, unknown>
|
|
472
462
|
)
|
|
473
463
|
}
|
|
464
|
+
const retired = Option.getOrUndefined(yield* Effect.serviceOption(CurrentRetirementLatch))
|
|
474
465
|
pending = {
|
|
475
466
|
workflowName: workflow._tag,
|
|
476
467
|
executionId,
|
|
477
468
|
results,
|
|
478
|
-
|
|
479
|
-
|
|
469
|
+
scope: Scope.makeUnsafe(),
|
|
470
|
+
retired,
|
|
471
|
+
idle: Latch.makeUnsafe(true),
|
|
472
|
+
executing: 0
|
|
480
473
|
}
|
|
481
474
|
yield* Scope.addFinalizer(activation, closeRuns(pending, true))
|
|
482
475
|
pendingByActivation.set(activation, pending)
|
|
@@ -488,6 +481,9 @@ export const make = Effect.gen(function*() {
|
|
|
488
481
|
readonly instance: WorkflowEngine.WorkflowInstance["Service"]
|
|
489
482
|
// Activity awaits must wake the run after suspension without preempting it.
|
|
490
483
|
readonly activityAwaits: Map<string, number>
|
|
484
|
+
// Set once the exiting run starts listing its parents, so a later
|
|
485
|
+
// `parent` registration waits for the reply and wakes its own parent.
|
|
486
|
+
completing: boolean
|
|
491
487
|
} | undefined
|
|
492
488
|
// Concurrent automatic wakes share one wait for the current run to
|
|
493
489
|
// publish its reply. Explicit wakes cannot be dropped, because an
|
|
@@ -509,17 +505,30 @@ export const make = Effect.gen(function*() {
|
|
|
509
505
|
)
|
|
510
506
|
)
|
|
511
507
|
)
|
|
508
|
+
// An asynchronous reply releases the RPC concurrency permit while
|
|
509
|
+
// the effect waits; the pending request still occupies mailbox capacity.
|
|
510
|
+
// The activation owns the fiber so it survives handler rebuilds,
|
|
511
|
+
// but activation shutdown still interrupts it for durable redelivery.
|
|
512
|
+
const forkReply = <A>(effect: Effect.Effect<A>) => {
|
|
513
|
+
const reply = Deferred.makeUnsafe<A>()
|
|
514
|
+
return effect.pipe(
|
|
515
|
+
Deferred.into(reply),
|
|
516
|
+
Effect.forkIn(activation, { startImmediately: true }),
|
|
517
|
+
Effect.as(reply)
|
|
518
|
+
)
|
|
519
|
+
}
|
|
512
520
|
return {
|
|
513
521
|
run: (request: Entity.Request<any>) => {
|
|
514
|
-
//
|
|
515
|
-
|
|
522
|
+
// A superseded instance retained by a finalizer no longer needs its wait sets.
|
|
523
|
+
currentRun?.instance.awaitedDeferreds.clear()
|
|
524
|
+
currentRun?.instance.completedDeferreds.clear()
|
|
516
525
|
const instance = WorkflowEngine.WorkflowInstance.initial(workflow, executionId, {
|
|
517
|
-
scope:
|
|
526
|
+
scope: reuseOrForkScope(currentRun?.instance.scope, pending.scope)
|
|
518
527
|
})
|
|
519
|
-
|
|
520
|
-
currentRun =
|
|
528
|
+
const current = { request, instance, activityAwaits: new Map<string, number>(), completing: false }
|
|
529
|
+
currentRun = current
|
|
521
530
|
const parent = (request.payload as any)[payloadParentKey] as
|
|
522
|
-
|
|
|
531
|
+
| (ParentRef & { readonly detached?: boolean })
|
|
523
532
|
| undefined
|
|
524
533
|
return execute(workflow.payloadSchema.make(request.payload) as object, executionId).pipe(
|
|
525
534
|
Effect.onExit((exit) => {
|
|
@@ -531,10 +540,19 @@ export const make = Effect.gen(function*() {
|
|
|
531
540
|
if (instance.abandoned) {
|
|
532
541
|
instance.suspended = false
|
|
533
542
|
}
|
|
534
|
-
// Abandoned runs never wake
|
|
535
|
-
const resumeParent =
|
|
536
|
-
|
|
537
|
-
:
|
|
543
|
+
// Abandoned runs never wake parents; another owner replays them.
|
|
544
|
+
const resumeParent = instance.abandoned ? Effect.void : ensureSuccess(Effect.gen(function*() {
|
|
545
|
+
current.completing = true
|
|
546
|
+
const parents = (yield* storage.requestsForAddress({ address, tag: "parent" }))
|
|
547
|
+
.map((registration) => registration.payload as ParentRef)
|
|
548
|
+
// Registrations are unique by parent; only an older caller's payload parent can repeat one.
|
|
549
|
+
if (parent && !parent.detached && !parents.some((ref) => sameParent(ref, parent))) {
|
|
550
|
+
parents.push(parent)
|
|
551
|
+
}
|
|
552
|
+
for (const ref of parents) {
|
|
553
|
+
yield* sendResumeParent(ref, executionId)
|
|
554
|
+
}
|
|
555
|
+
}))
|
|
538
556
|
if (
|
|
539
557
|
!instance.suspended &&
|
|
540
558
|
!instance.abandoned &&
|
|
@@ -613,9 +631,12 @@ export const make = Effect.gen(function*() {
|
|
|
613
631
|
Context.add(CurrentActivationScope, activation),
|
|
614
632
|
Context.add(Activity.CurrentAttempt, payload.attempt)
|
|
615
633
|
)
|
|
634
|
+
pending.executing++
|
|
635
|
+
pending.idle.closeUnsafe()
|
|
616
636
|
return entry.activity.executeEncoded.pipe(
|
|
617
637
|
Effect.provideContext(context),
|
|
618
638
|
Workflow.intoResult,
|
|
639
|
+
Effect.provideService(RetryingExecution, Context.get(entry.context, RetryingExecution)),
|
|
619
640
|
Effect.tap((result) =>
|
|
620
641
|
Effect.sync(() => {
|
|
621
642
|
entry.result = result
|
|
@@ -629,6 +650,9 @@ export const make = Effect.gen(function*() {
|
|
|
629
650
|
)
|
|
630
651
|
return suspend ? Effect.succeed(new Workflow.Suspended({})) : Effect.failCause(cause)
|
|
631
652
|
}),
|
|
653
|
+
Effect.ensuring(Effect.sync(() => {
|
|
654
|
+
if (--pending.executing === 0) pending.idle.openUnsafe()
|
|
655
|
+
})),
|
|
632
656
|
Effect.provideService(WorkflowEngine.WorkflowInstance, instance),
|
|
633
657
|
Effect.provideService(Activity.CurrentAttempt, payload.attempt),
|
|
634
658
|
Rpc.wrap({ fork: true, uninterruptible: true })
|
|
@@ -659,24 +683,32 @@ export const make = Effect.gen(function*() {
|
|
|
659
683
|
Effect.andThen(resumeCurrentRun(mode))
|
|
660
684
|
)
|
|
661
685
|
)
|
|
662
|
-
|
|
663
|
-
// the wake waits; the pending request still occupies mailbox capacity.
|
|
664
|
-
// The activation owns the wake so it survives handler rebuilds,
|
|
665
|
-
// but activation shutdown still interrupts it for durable redelivery.
|
|
666
|
-
const reply = Deferred.makeUnsafe<Exit.Exit<unknown, unknown>>()
|
|
667
|
-
return wake.pipe(
|
|
668
|
-
Effect.as(payload.exit),
|
|
669
|
-
Deferred.into(reply),
|
|
670
|
-
Effect.forkIn(activation, { startImmediately: true }),
|
|
671
|
-
Effect.as(reply)
|
|
672
|
-
)
|
|
686
|
+
return forkReply(Effect.as(wake, payload.exit as Exit.Exit<unknown, unknown>))
|
|
673
687
|
},
|
|
674
688
|
|
|
675
|
-
resume: () => resumeCurrentRun("automatic").pipe(Rpc.wrap({ fork: true, uninterruptible: true }))
|
|
689
|
+
resume: () => resumeCurrentRun("automatic").pipe(Rpc.wrap({ fork: true, uninterruptible: true })),
|
|
690
|
+
|
|
691
|
+
parent: (request: Entity.Request<any>) => {
|
|
692
|
+
const ref = request.payload as ParentRef
|
|
693
|
+
// The exiting run may have listed parents before this
|
|
694
|
+
// registration; wait for its reply, then wake.
|
|
695
|
+
if (currentRun?.completing) {
|
|
696
|
+
return forkReply(
|
|
697
|
+
ensureSuccess(
|
|
698
|
+
Effect.andThen(waitForRunReply(workflow, currentRun.request), sendResumeParent(ref, executionId))
|
|
699
|
+
)
|
|
700
|
+
)
|
|
701
|
+
}
|
|
702
|
+
return Effect.gen(function*() {
|
|
703
|
+
if (isRunSettled(yield* retryPersistence(runReply(workflow, executionId)))) {
|
|
704
|
+
yield* ensureSuccess(sendResumeParent(ref, executionId))
|
|
705
|
+
}
|
|
706
|
+
}).pipe(Rpc.wrap({ fork: true }))
|
|
707
|
+
}
|
|
676
708
|
}
|
|
677
709
|
}),
|
|
678
|
-
// Alongside the run, let deferred handlers briefly acquire a
|
|
679
|
-
// fork their wake and return an asynchronous reply.
|
|
710
|
+
// Alongside the run, let deferred and `parent` handlers briefly acquire a
|
|
711
|
+
// permit to fork their wake and return an asynchronous reply.
|
|
680
712
|
{ concurrency: 2, maxIdleTime: entityMaxIdleTime }
|
|
681
713
|
) as Effect.Effect<void, never, Scope.Scope>
|
|
682
714
|
if (existing === undefined || existing === workflow) return registration
|
|
@@ -692,20 +724,35 @@ export const make = Effect.gen(function*() {
|
|
|
692
724
|
execute: (workflow, { detached, discard, executionId, parent, payload }) => {
|
|
693
725
|
ensureEntity(workflow)
|
|
694
726
|
return RcMap.get(clients, workflow._tag).pipe(
|
|
695
|
-
Effect.flatMap((make) =>
|
|
696
|
-
make(executionId)
|
|
697
|
-
|
|
727
|
+
Effect.flatMap((make) => {
|
|
728
|
+
const client = make(executionId)
|
|
729
|
+
// The shard group lets a runner without the parent's workflow address its wake.
|
|
730
|
+
const shardGroup = parent && !detached ? shardGroupFor(parent.workflow, parent.executionId) : "default"
|
|
731
|
+
const ref: ParentRef | undefined = parent && {
|
|
732
|
+
workflowName: parent.workflow._tag,
|
|
733
|
+
executionId: parent.executionId,
|
|
734
|
+
...(shardGroup === "default" ? undefined : { shardGroup })
|
|
735
|
+
}
|
|
736
|
+
const run = client.run(
|
|
737
|
+
ref ?
|
|
698
738
|
{
|
|
699
739
|
...payload,
|
|
700
740
|
// A detached child keeps its parent for observability only.
|
|
701
|
-
[payloadParentKey]: detached
|
|
702
|
-
? { workflowName: parent.workflow._tag, executionId: parent.executionId, detached: true }
|
|
703
|
-
: { workflowName: parent.workflow._tag, executionId: parent.executionId }
|
|
741
|
+
[payloadParentKey]: detached ? { ...ref, detached: true } : ref
|
|
704
742
|
} :
|
|
705
743
|
payload,
|
|
706
744
|
{ discard }
|
|
707
745
|
)
|
|
708
|
-
|
|
746
|
+
if (!ref || detached || sameParent(ref, { workflowName: workflow._tag, executionId })) {
|
|
747
|
+
return run
|
|
748
|
+
}
|
|
749
|
+
// Discarded, so an open transaction or an older runner cannot block it.
|
|
750
|
+
const register = Effect.flatMap(
|
|
751
|
+
runReply(workflow, executionId),
|
|
752
|
+
(reply) => isRunSettled(reply) ? Effect.void : client.parent(ref, { discard: true })
|
|
753
|
+
)
|
|
754
|
+
return Effect.andThen(register, run)
|
|
755
|
+
}),
|
|
709
756
|
// A failed save inside a workflow would be stored as its result. Top-level
|
|
710
757
|
// calls still fail, so their callers are not blocked during an outage.
|
|
711
758
|
parent ? retryPersistence : Effect.orDie,
|
|
@@ -716,13 +763,7 @@ export const make = Effect.gen(function*() {
|
|
|
716
763
|
poll: Effect.fnUntraced(function*(workflow, executionId) {
|
|
717
764
|
const entity = ensureEntity(workflow)
|
|
718
765
|
const exitSchema = Schema.toCodecJson(Rpc.exitSchema(entity.protocol.requests.get("run")!))
|
|
719
|
-
const reply = yield*
|
|
720
|
-
workflow,
|
|
721
|
-
entityType: `Workflow/${workflow._tag}`,
|
|
722
|
-
executionId,
|
|
723
|
-
tag: "run",
|
|
724
|
-
id: ""
|
|
725
|
-
})
|
|
766
|
+
const reply = yield* runReply(workflow, executionId)
|
|
726
767
|
if (Option.isNone(reply)) return Option.none()
|
|
727
768
|
const exit = yield* (Schema.decodeUnknownEffect(exitSchema)(reply.value.exit) as Effect.Effect<
|
|
728
769
|
Exit.Exit<any, any>,
|
|
@@ -791,14 +832,25 @@ export const make = Effect.gen(function*() {
|
|
|
791
832
|
if (activities.get(activityId) === entry) activities.delete(activityId)
|
|
792
833
|
})
|
|
793
834
|
)
|
|
835
|
+
const activation = yield* Effect.serviceOption(CurrentActivationScope)
|
|
836
|
+
const pending = Option.isSome(activation) ? pendingByActivation.get(activation.value) : undefined
|
|
837
|
+
const handoff = pending?.retired &&
|
|
838
|
+
pending.workflowName === instance.workflow._tag &&
|
|
839
|
+
pending.executionId === instance.executionId
|
|
840
|
+
? Effect.andThen(pending.retired.await, Effect.as(pending.idle.await, Option.none()))
|
|
841
|
+
: Effect.never
|
|
794
842
|
while (true) {
|
|
795
|
-
const
|
|
843
|
+
const maybeResult = yield* retryPersistence(
|
|
796
844
|
client.activity({
|
|
797
845
|
name: activity.name,
|
|
798
846
|
attempt,
|
|
799
847
|
withTransaction: Context.get(activity.annotations, ClusterSchema.WithTransaction)
|
|
800
848
|
})
|
|
801
|
-
)
|
|
849
|
+
).pipe(Effect.asSome, Effect.raceFirst(handoff))
|
|
850
|
+
// The retired entity will not run this activity. Leave the run for
|
|
851
|
+
// the next owner, which replays it and reads the saved results.
|
|
852
|
+
if (Option.isNone(maybeResult)) return yield* ClusterAbandon.interrupt
|
|
853
|
+
const result = maybeResult.value
|
|
802
854
|
// If the activity has suspended and did not execute, we need to resume
|
|
803
855
|
// it by resetting the attempt and re-executing.
|
|
804
856
|
if (
|
|
@@ -995,15 +1047,22 @@ interface ActivationState {
|
|
|
995
1047
|
readonly workflowName: string
|
|
996
1048
|
readonly executionId: string
|
|
997
1049
|
readonly results: Map<string, Exit.Exit<unknown, unknown>>
|
|
998
|
-
//
|
|
999
|
-
//
|
|
1050
|
+
// Parent of every run's scope, so runs that suspended keep their resources
|
|
1051
|
+
// and durable finalizers until the execution finishes.
|
|
1000
1052
|
scope: Scope.Closeable
|
|
1001
|
-
|
|
1053
|
+
// Opens when this activation retires; paired with `idle` so in-flight
|
|
1054
|
+
// activities finish before any waiting run hands off to the next owner.
|
|
1055
|
+
readonly retired: Latch.Latch | undefined
|
|
1056
|
+
readonly idle: Latch.Latch
|
|
1057
|
+
executing: number
|
|
1002
1058
|
}
|
|
1003
1059
|
|
|
1004
1060
|
const isSuspendedReply = (reply: WithExitEncoded<Workflow.ResultEncoded<any, any>>) =>
|
|
1005
1061
|
reply.exit._tag === "Success" && reply.exit.value._tag === "Suspended"
|
|
1006
1062
|
|
|
1063
|
+
const isRunSettled = (reply: Option.Option<WithExitEncoded<Workflow.ResultEncoded<any, any>>>) =>
|
|
1064
|
+
Option.isSome(reply) && !isSuspendedReply(reply.value)
|
|
1065
|
+
|
|
1007
1066
|
const isFailedReply = (reply: WithExitEncoded<Workflow.ResultEncoded<any, any>>) =>
|
|
1008
1067
|
reply.exit._tag === "Success" && reply.exit.value._tag === "Suspended" && reply.exit.value.failed === true
|
|
1009
1068
|
|
|
@@ -1024,6 +1083,24 @@ const ResumeRpc = Rpc.make("resume", {
|
|
|
1024
1083
|
.annotate(ClusterSchema.Persisted, true)
|
|
1025
1084
|
.annotate(ClusterSchema.Uninterruptible, "server")
|
|
1026
1085
|
|
|
1086
|
+
const ParentRefSchema = Schema.Struct({
|
|
1087
|
+
workflowName: Schema.String,
|
|
1088
|
+
executionId: Schema.String,
|
|
1089
|
+
shardGroup: Schema.optional(Schema.String)
|
|
1090
|
+
})
|
|
1091
|
+
type ParentRef = typeof ParentRefSchema.Type
|
|
1092
|
+
|
|
1093
|
+
// The shard group only routes the wake, so it is not part of a parent's identity.
|
|
1094
|
+
const sameParent = (a: ParentRef, b: ParentRef) => a.workflowName === b.workflowName && a.executionId === b.executionId
|
|
1095
|
+
|
|
1096
|
+
const ParentRpc = Rpc.make("parent", {
|
|
1097
|
+
payload: ParentRefSchema.fields,
|
|
1098
|
+
// Length-prefixed so an execution id containing a separator cannot collide.
|
|
1099
|
+
primaryKey: (parent) => `${parent.workflowName.length}:${parent.workflowName}:${parent.executionId}`
|
|
1100
|
+
})
|
|
1101
|
+
.annotate(ClusterSchema.Persisted, true)
|
|
1102
|
+
.annotate(ClusterSchema.Uninterruptible, "server")
|
|
1103
|
+
|
|
1027
1104
|
const payloadParentKey = "~effect/cluster/ClusterWorkflowEngine/payloadParentKey"
|
|
1028
1105
|
|
|
1029
1106
|
// Workflow state is durable, so an idle entity (completed or suspended) can
|
|
@@ -1038,8 +1115,7 @@ const makeWorkflowEntity = (workflow: Workflow.Any) =>
|
|
|
1038
1115
|
payload: {
|
|
1039
1116
|
...workflow.payloadSchema.fields,
|
|
1040
1117
|
[payloadParentKey]: Schema.optional(Schema.Struct({
|
|
1041
|
-
|
|
1042
|
-
executionId: Schema.String,
|
|
1118
|
+
...ParentRefSchema.fields,
|
|
1043
1119
|
detached: Schema.optional(Schema.Boolean)
|
|
1044
1120
|
}))
|
|
1045
1121
|
},
|
|
@@ -1054,13 +1130,13 @@ const makeWorkflowEntity = (workflow: Workflow.Any) =>
|
|
|
1054
1130
|
|
|
1055
1131
|
DeferredRpc,
|
|
1056
1132
|
ResumeRpc,
|
|
1133
|
+
ParentRpc,
|
|
1057
1134
|
ActivityRpc
|
|
1058
1135
|
]).annotateMerge(workflow.annotations)
|
|
1059
1136
|
|
|
1060
1137
|
const makePartialWorkflowEntity = (workflowName: string) =>
|
|
1061
1138
|
Entity.make(`Workflow/${workflowName}`, [
|
|
1062
1139
|
DeferredRpc,
|
|
1063
|
-
ResumeRpc,
|
|
1064
1140
|
ActivityRpc
|
|
1065
1141
|
])
|
|
1066
1142
|
|
|
@@ -118,6 +118,23 @@ export class MessageStorage extends Context.Service<MessageStorage, {
|
|
|
118
118
|
}
|
|
119
119
|
) => Effect.Effect<Option.Option<Snowflake.Snowflake>, PersistenceError>
|
|
120
120
|
|
|
121
|
+
/**
|
|
122
|
+
* Retrieves every request saved for the address under the RPC tag, whether
|
|
123
|
+
* or not it has been processed, in no particular order.
|
|
124
|
+
*
|
|
125
|
+
* **Details**
|
|
126
|
+
*
|
|
127
|
+
* The entity type, entity id and tag must match exactly, including case. The
|
|
128
|
+
* shard id is ignored, as in `clearAddress`, so requests saved before a shard
|
|
129
|
+
* reassignment are still returned.
|
|
130
|
+
*/
|
|
131
|
+
readonly requestsForAddress: (
|
|
132
|
+
options: {
|
|
133
|
+
readonly address: EntityAddress
|
|
134
|
+
readonly tag: string
|
|
135
|
+
}
|
|
136
|
+
) => Effect.Effect<Array<Envelope.PartialRequestEncoded>, PersistenceError>
|
|
137
|
+
|
|
121
138
|
/**
|
|
122
139
|
* For locally sent messages, register a handler to process the replies.
|
|
123
140
|
*
|
|
@@ -418,6 +435,23 @@ export type Encoded = {
|
|
|
418
435
|
primaryKey: string
|
|
419
436
|
) => Effect.Effect<Option.Option<Snowflake.Snowflake>, PersistenceError>
|
|
420
437
|
|
|
438
|
+
/**
|
|
439
|
+
* Retrieves every request saved for the address under the RPC tag, whether
|
|
440
|
+
* or not it has been processed, in no particular order.
|
|
441
|
+
*
|
|
442
|
+
* **Details**
|
|
443
|
+
*
|
|
444
|
+
* The entity type, entity id and tag must match exactly, including case. The
|
|
445
|
+
* shard id is ignored, as in `clearAddress`, so requests saved before a shard
|
|
446
|
+
* reassignment are still returned.
|
|
447
|
+
*/
|
|
448
|
+
readonly requestsForAddress: (
|
|
449
|
+
options: {
|
|
450
|
+
readonly address: EntityAddress
|
|
451
|
+
readonly tag: string
|
|
452
|
+
}
|
|
453
|
+
) => Effect.Effect<Array<Envelope.PartialRequestEncoded>, PersistenceError>
|
|
454
|
+
|
|
421
455
|
/**
|
|
422
456
|
* Retrieves the replies for the specified requests.
|
|
423
457
|
*
|
|
@@ -659,9 +693,11 @@ export const make = (
|
|
|
659
693
|
handlers.push(entry)
|
|
660
694
|
shardSet.add(entry)
|
|
661
695
|
return Effect.sync(() => {
|
|
662
|
-
|
|
663
|
-
handlers.splice(index, 1)
|
|
696
|
+
handlers.splice(handlers.indexOf(entry), 1)
|
|
664
697
|
shardSet.delete(entry)
|
|
698
|
+
if (handlers.length === 0 && replyHandlers.get(requestId) === handlers) {
|
|
699
|
+
replyHandlers.delete(requestId)
|
|
700
|
+
}
|
|
665
701
|
})
|
|
666
702
|
})
|
|
667
703
|
},
|
|
@@ -815,6 +851,7 @@ export const makeEncoded: (encoded: Encoded) => Effect.Effect<
|
|
|
815
851
|
const primaryKey = Envelope.primaryKeyByAddress(options)
|
|
816
852
|
return encoded.requestIdForPrimaryKey(primaryKey)
|
|
817
853
|
},
|
|
854
|
+
requestsForAddress: encoded.requestsForAddress,
|
|
818
855
|
unprocessedMessages(shardIds, options) {
|
|
819
856
|
const storage = this as unknown as MessageStorage["Service"]
|
|
820
857
|
const shards = Array.from(shardIds, (id) => id.toString())
|
|
@@ -965,6 +1002,7 @@ export const noop: MessageStorage["Service"] = Effect.runSync(make({
|
|
|
965
1002
|
repliesFor: () => Effect.succeed([]),
|
|
966
1003
|
repliesForUnfiltered: () => Effect.succeed([]),
|
|
967
1004
|
requestIdForPrimaryKey: () => Effect.succeedNone,
|
|
1005
|
+
requestsForAddress: () => Effect.succeed([]),
|
|
968
1006
|
unprocessedMessages: () => Effect.succeed([]),
|
|
969
1007
|
unprocessedMessagesById: () => Effect.succeed([]),
|
|
970
1008
|
resetAddress: () => Effect.void,
|
|
@@ -1179,6 +1217,17 @@ export class MemoryDriver extends Context.Service<MemoryDriver>()("effect/cluste
|
|
|
1179
1217
|
const entry = requestsByPrimaryKey.get(primaryKey)
|
|
1180
1218
|
return Option.map(Option.fromNullishOr(entry?.envelope.requestId), Snowflake.Snowflake)
|
|
1181
1219
|
}),
|
|
1220
|
+
requestsForAddress: ({ address, tag }) =>
|
|
1221
|
+
Effect.sync(() => {
|
|
1222
|
+
const out: Array<Envelope.PartialRequestEncoded> = []
|
|
1223
|
+
for (const { envelope } of requests.values()) {
|
|
1224
|
+
if (
|
|
1225
|
+
envelope._tag === "Request" && envelope.tag === tag &&
|
|
1226
|
+
envelope.address.entityType === address.entityType && envelope.address.entityId === address.entityId
|
|
1227
|
+
) out.push(envelope)
|
|
1228
|
+
}
|
|
1229
|
+
return out
|
|
1230
|
+
}),
|
|
1182
1231
|
repliesFor: (requestIds) => Effect.sync(() => repliesFor(requestIds)),
|
|
1183
1232
|
repliesForUnfiltered: (requestIds) =>
|
|
1184
1233
|
Effect.sync(() => requestIds.flatMap((id) => requests.get(String(id))?.replies ?? [])),
|