dockerfile/examples/standardnotes/official-src/server-main/packages/auth/bin/stats.ts

39 lines
1.1 KiB
TypeScript
Raw Permalink Normal View History

2024-03-15 14:52:38 +08:00
import 'reflect-metadata'
import { Logger } from 'winston'
import { TimerInterface } from '@standardnotes/time'
import { ContainerConfigLoader } from '../src/Bootstrap/Container'
import TYPES from '../src/Bootstrap/Types'
import { Env } from '../src/Bootstrap/Env'
import { PersistStatistics } from '../src/Domain/UseCase/PersistStatistics/PersistStatistics'
const container = new ContainerConfigLoader('worker')
void container.load().then((container) => {
const env: Env = new Env()
env.load()
const logger: Logger = container.get(TYPES.Auth_Logger)
logger.info('Starting statistics persistence...')
const persistStats: PersistStatistics = container.get(TYPES.Auth_PersistStatistics)
const timer: TimerInterface = container.get(TYPES.Auth_Timer)
Promise.resolve(
persistStats.execute({
sessionsInADay: timer.getUTCDateNDaysAgo(1),
}),
)
.then(() => {
logger.info('Stats persisted.')
process.exit(0)
})
.catch((error) => {
logger.error(`Could not persist stats: ${error.message}`)
process.exit(1)
})
})