Skip to content

Instantly share code, notes, and snippets.

@titouancreach
Created August 8, 2024 07:35
Show Gist options
  • Save titouancreach/dd146383dd696d6e4343c3a28022b3ff to your computer and use it in GitHub Desktop.
Save titouancreach/dd146383dd696d6e4343c3a28022b3ff to your computer and use it in GitHub Desktop.
import { NodeRuntime } from '@effect/platform-node'
import { Database } from '@repo/shared/Database'
import { SqsService } from '@repo/shared/SqsService'
import { Config, Effect, Layer, LogLevel, Logger } from 'effect'
import { withMinimumLogLevel } from 'effect/Logger'
import * as DemoMessageConsumer from './Features/Demo/DemoMessageConsumer'
const consumers = [DemoMessageConsumer.consumer]
const dependencies = Layer.mergeAll(
SqsService.Live,
Logger.pretty,
Database.Live,
)
const preRunEffect = Effect.gen(function* () {
const env = yield* Config.string('NODE_ENV').pipe(
Config.withDefault('development'),
)
yield* Effect.logInfo(`Starting, with NODE_ENV: ${env}`)
})
const program = preRunEffect.pipe(
Effect.andThen(Effect.all(consumers, { concurrency: 'unbounded' })),
Effect.andThen(Effect.never),
withMinimumLogLevel(LogLevel.Debug),
Effect.provide(dependencies),
Effect.scoped,
Effect.catchAllCause(Effect.logError),
)
NodeRuntime.runMain(program)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment