stat-sync.ts 872 B

12345678910111213141516171819202122
  1. import * as NodeRuntime from "@effect/platform-node/NodeRuntime"
  2. import { Athena } from "@opencode-ai/stats-core/athena"
  3. import { layer as statsLayer } from "@opencode-ai/stats-core/runtime"
  4. import { syncStats } from "@opencode-ai/stats-core/stat-sync"
  5. import { Cause, Effect, Layer, Schedule } from "effect"
  6. const SYNC_INTERVAL = "1 hour"
  7. const runtimeLayer = Layer.mergeAll(statsLayer, Athena.layer)
  8. const syncPass = syncStats().pipe(
  9. Effect.catchCause((cause) =>
  10. Effect.logWarning(`stats sync failed ${JSON.stringify({ cause: Cause.pretty(cause) })}`),
  11. ),
  12. )
  13. const daemon = Effect.logInfo("stats sync daemon started").pipe(
  14. Effect.andThen(syncPass.pipe(Effect.repeat(Schedule.fixed(SYNC_INTERVAL)))),
  15. Effect.forkScoped,
  16. )
  17. NodeRuntime.runMain(Layer.launch(Layer.effectDiscard(daemon).pipe(Layer.provide(runtimeLayer))), {
  18. disableErrorReporting: true,
  19. })