Created
August 8, 2024 07:35
-
-
Save titouancreach/dd146383dd696d6e4343c3a28022b3ff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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