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

Function activity

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

Source from the content-addressed store, hash-verified

679 },
680
681 activity(request: Entity.Request<any>) {
682 const payload = request.payload as { name: string; attempt: number; withTransaction: boolean }
683 const activityId = activityRegistrationKey(executionId, payload.name, payload.attempt)
684 const instance = WorkflowEngine.WorkflowInstance.initial(workflow, executionId, {
685 awaitedDeferreds: currentRun?.activityAwaits
686 })
687 const entry = activities.get(activityId)
688 if (!entry) {
689 // Replay may never register a losing race activity. Answer it
690 // without waiting; a later registration can reset this reply.
691 return Effect.succeed(new Workflow.Suspended({})).pipe(Rpc.wrap({ fork: true }))
692 }
693 // The request is redelivered when its reply could not be saved.
694 // A transaction rolled the activity back, so it runs again.
695 if (entry.result && !payload.withTransaction) {
696 return Effect.succeed(entry.result).pipe(Rpc.wrap({ fork: true }))
697 }
698 const context = entry.context.pipe(
699 Context.add(WorkflowEngine.WorkflowInstance, instance),
700 Context.add(CurrentActivationScope, activation),
701 Context.add(Activity.CurrentAttempt, payload.attempt)
702 )
703 pending.executing++
704 pending.idle.closeUnsafe()
705 return entry.activity.executeEncoded.pipe(
706 Effect.provideContext(context),
707 Workflow.intoResult,
708 Effect.provideService(RetryingExecution, Context.get(entry.context, RetryingExecution)),
709 Effect.tap((result) =>
710 Effect.sync(() => {
711 entry.result = result
712 })
713 ),
714 Effect.catchCause((cause) => {
715 // we only want to store interrupts as suspends when the
716 // client requested it
717 const suspend = cause.reasons.some((f) =>
718 f._tag === "Interrupt" && f.annotations.has(ClientAbort.key)
719 )
720 return suspend ? Effect.succeed(new Workflow.Suspended({})) : Effect.failCause(cause)
721 }),
722 Effect.ensuring(Effect.sync(() => {
723 if (--pending.executing === 0) pending.idle.openUnsafe()
724 })),
725 Effect.provideService(WorkflowEngine.WorkflowInstance, instance),
726 Effect.provideService(Activity.CurrentAttempt, payload.attempt),
727 Rpc.wrap({ fork: true, uninterruptible: true })
728 )
729 },
730
731 deferred: (request: Entity.Request<any>) => {
732 const payload = request.payload as any

Callers

nothing calls this directly

Calls 12

activityRegistrationKeyFunction · 0.85
initialMethod · 0.80
wrapMethod · 0.80
someMethod · 0.80
getMethod · 0.65
pipeMethod · 0.65
addMethod · 0.65
closeUnsafeMethod · 0.65
hasMethod · 0.65
openUnsafeMethod · 0.65
succeedMethod · 0.45
syncMethod · 0.45

Tested by

no test coverage detected