MCPcopy Create free account
hub / github.com/Effect-TS/effect / activity

Function activity

packages/cluster/src/ClusterWorkflowEngine.ts:341–388  ·  view source on GitHub ↗
(request: Entity.Request<any>)

Source from the content-addressed store, hash-verified

339 },
340
341 activity(request: Entity.Request<any>) {
342 const activityId = `${executionId}/${request.payload.name}`
343 const instance = WorkflowInstance.initial(workflow, executionId)
344 interruptedActivities.delete(activityId)
345 return Effect.gen(function*() {
346 let entry = activities.get(activityId)
347 while (!entry) {
348 const latch = Effect.unsafeMakeLatch()
349 activityLatches.set(activityId, latch)
350 yield* latch.await
351 entry = activities.get(activityId)
352 }
353 const contextMap = new Map(entry.runtime.context.unsafeMap)
354 contextMap.set(Activity.CurrentAttempt.key, request.payload.attempt)
355 contextMap.set(WorkflowInstance.key, instance)
356 const runtime = Runtime.make({
357 context: Context.unsafeMake(contextMap),
358 fiberRefs: entry.runtime.fiberRefs,
359 runtimeFlags: Runtime.defaultRuntimeFlags
360 })
361 return yield* entry.activity.executeEncoded.pipe(
362 Effect.provide(runtime)
363 )
364 }).pipe(
365 Workflow.intoResult,
366 Effect.catchAllCause((cause) => {
367 const interruptors = Cause.interruptors(cause)
368 // we only want to store interrupts as suspends when the
369 // client requested it
370 const ids = Array.from(interruptors, (id) => Array.from(FiberId.ids(id))).flat()
371 const suspend = ids.includes(RpcServer.fiberIdClientInterrupt.id)
372 if (suspend) {
373 interruptedActivities.add(activityId)
374 return Effect.succeed(new Workflow.Suspended())
375 }
376 return Effect.failCause(cause)
377 }),
378 Effect.provideService(WorkflowInstance, instance),
379 Effect.provideService(Activity.CurrentAttempt, request.payload.attempt),
380 Effect.ensuring(Effect.sync(() => {
381 activities.delete(activityId)
382 })),
383 Rpc.wrap({
384 fork: true,
385 uninterruptible: true
386 })
387 )
388 },
389
390 deferred: Effect.fnUntraced(function*(request: Entity.Request<any>) {
391 yield* ensureSuccess(resume(workflow, executionId))

Callers

nothing calls this directly

Calls 10

initialMethod · 0.80
failCauseMethod · 0.80
syncMethod · 0.80
wrapMethod · 0.80
pipeMethod · 0.65
getMethod · 0.65
setMethod · 0.65
makeMethod · 0.65
provideMethod · 0.65
addMethod · 0.65

Tested by

no test coverage detected