Skip to content

Instantly share code, notes, and snippets.

@macklinu
Created July 30, 2025 13:40
Show Gist options
  • Save macklinu/2a6a61ba617c0a06120df2752fd1418c to your computer and use it in GitHub Desktop.
Save macklinu/2a6a61ba617c0a06120df2752fd1418c to your computer and use it in GitHub Desktop.
Trying to get ClusterCron logging every minute
import * as ClusterCron from '@effect/cluster/ClusterCron'
import * as ClusterWorkflowEngine from '@effect/cluster/ClusterWorkflowEngine'
import * as RunnerAddress from '@effect/cluster/RunnerAddress'
import * as NodeClusterRunnerSocket from '@effect/platform-node/NodeClusterRunnerSocket'
import * as NodeRuntime from '@effect/platform-node/NodeRuntime'
import { TracerLayer } from '@my-app/open-telemetry/Tracer'
import { SqlClientLayer } from '@my-app/sql/SqlClient'
import * as Config from 'effect/Config'
import * as Cron from 'effect/Cron'
import * as Effect from 'effect/Effect'
import * as Layer from 'effect/Layer'
import * as Option from 'effect/Option'
const RunnerLayer = Layer.unwrapEffect(
Effect.gen(function* () {
const port = yield* Config.number('PORT')
const shardManagerPort = yield* Config.number('SHARD_MANAGER_PORT')
// TODO: Update with production configuration
const runnerIp = 'localhost'
const shardManagerHost = 'localhost'
const listenHost = 'localhost'
return NodeClusterRunnerSocket.layer({
storage: 'sql',
shardingConfig: {
runnerAddress: Option.some(RunnerAddress.make(runnerIp, port)),
runnerListenAddress: Option.some(RunnerAddress.make(listenHost, port)),
shardManagerAddress: RunnerAddress.make(
shardManagerHost,
shardManagerPort
),
},
})
})
)
const TestCron = ClusterCron.make({
name: 'TestCron',
cron: Cron.unsafeParse('* * * * *'),
execute: Effect.gen(function* () {
yield* Effect.logInfo('TestCron executed')
}).pipe(Effect.withSpan('TestCron.execute')),
})
TestCron.pipe(
Layer.provide(ClusterWorkflowEngine.layer),
Layer.provide(RunnerLayer),
Layer.provide(SqlClientLayer),
Layer.provide(TracerLayer),
Layer.launch,
NodeRuntime.runMain
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment