Убран лишний код. Скорректированы docker и package файлы. Переработано взаимодействие с бд - упрощена логика.
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { distinctUntilChanged, from, map, Observable, switchMap, timer } from 'rxjs';
|
||||
import { getIntegerConfig } from '../common/config-number';
|
||||
import { CurrentResponseDto } from './dto/current-response.dto';
|
||||
import { GetCurrentDto } from './dto/get-current.dto';
|
||||
import { CurrentService } from './current.service';
|
||||
@@ -15,21 +13,13 @@ type CurrentSnapshot = {
|
||||
response: CurrentResponseDto;
|
||||
};
|
||||
|
||||
const DEFAULT_CURRENT_EVENTS_POLL_MS = 1_000;
|
||||
|
||||
@Injectable()
|
||||
export class CurrentEventsService {
|
||||
constructor(
|
||||
private readonly current: CurrentService,
|
||||
private readonly config: ConfigService,
|
||||
) {}
|
||||
constructor(private readonly current: CurrentService) {}
|
||||
|
||||
/** Отправляет SSE-события current только при изменении снимка данных по edge/tags. */
|
||||
stream(query: GetCurrentDto): Observable<CurrentSseMessage> {
|
||||
const pollMs = Math.max(
|
||||
getIntegerConfig(this.config, 'CURRENT_EVENTS_POLL_MS', DEFAULT_CURRENT_EVENTS_POLL_MS),
|
||||
250,
|
||||
);
|
||||
const pollMs = Number(process.env.CURRENT_EVENTS_POLL_MS);
|
||||
|
||||
return timer(0, pollMs).pipe(
|
||||
switchMap(() => from(this.createSnapshot(query))),
|
||||
|
||||
Reference in New Issue
Block a user