Effect CommunityEC
Effect Community3mo ago
9 replies
Stephen Bluck

Missing Layer Causes Runtime Error with WorkflowEngine

I noticed there's a bit of a foot gun around ensuring you have provided the correct WorkflowEngine. Taking the example in the @effect/worker docs, I could remove the EmailWorkflowLayer and it all still compiles and I get a runtime error when .execute is invoked because the layer is obviously missing. Is there something I am missing or is there a workaround?

// To integrate with @effect/cluster, you can use the
// `ClusterWorkflowEngine.layer` Layer, and provide it with your cluster Runner
// layer.
const WorkflowEngineLayer = ClusterWorkflowEngine.layer.pipe(
  Layer.provideMerge(NodeClusterRunnerSocket.layer({ storage: 'sql' })),
  Layer.provideMerge(
    PgClient.layer({
      database: 'effect_cluster',
      username: 'cluster',
      password: Redacted.make('cluster')
    })
  )
);

// const EnvLayer = Layer.mergeAll(
//   EmailWorkflowLayer
//   // You can add any other cluster entities or workflow layers here
// ).pipe(Layer.provide(WorkflowEngineLayer));
const EnvLayer = WorkflowEngineLayer

// Finally, you can execute a workflow using the `.execute` method.
EmailWorkflow.execute({ id: '123', to: 'hello@timsmart.co' }).pipe(Effect.provide(EnvLayer), NodeRuntime.runMain);
Was this page helpful?