Download src/utils/intervalService.ts from lynfera/api: direct link, hf CLI and curl.
- Browser
- Download file 1.05 kB
-
https://huggingface.co/spaces/lynfera/api/resolve/c044fc22a5e2de895ca9282affe402eeab2b7f3d/src/utils/intervalService.ts
- Command line
-
hf download hf://spaces/lynfera/api@c044fc22a5e2de895ca9282affe402eeab2b7f3d/src/utils/intervalService.ts
-
curl -L -o intervalService.ts https://huggingface.co/spaces/lynfera/api/resolve/c044fc22a5e2de895ca9282affe402eeab2b7f3d/src/utils/intervalService.ts
1.05 kB
| import { IAnalyticsService } from "@/interfaces/service/IAnalyticsService.js"; | |
| import { ILogsService } from "@/interfaces/service/ILogsService.js"; | |
| class IntervalManager { | |
| private flushTimer?: NodeJS.Timeout; | |
| private readonly FLUSH_INTERVAL = 1000 * 10; // 10 seconds | |
| private analyticsService: IAnalyticsService; | |
| private logsService: ILogsService; | |
| constructor(logsSvcs: ILogsService, analyticsSvsc: IAnalyticsService) { | |
| this.analyticsService = analyticsSvsc; | |
| this.logsService = logsSvcs; | |
| this.startFlushTimer(); | |
| } | |
| private startFlushTimer(): void { | |
| this.flushTimer = setInterval(async () => { | |
| // process.stdout.write(" -"); | |
| await this.flushAll(); | |
| }, this.FLUSH_INTERVAL); | |
| } | |
| private async flushAll(): Promise<void> { | |
| await Promise.allSettled([this.analyticsService.saveBatch(), this.logsService.saveBatch()]); | |
| } | |
| async exitService(): Promise<void> { | |
| clearInterval(this.flushTimer); | |
| await Promise.allSettled([this.analyticsService.exitService(), this.logsService.exitService()]); | |
| } | |
| } | |
| export default IntervalManager; | |