Add setLoggingInterval method and implementation for tests and other purposes.

Let users control the logging interval of both parking repositories.
This commit is contained in:
2025-07-02 19:47:44 -04:00
parent 868a9f3b1d
commit 19336ce6ec
4 changed files with 57 additions and 42 deletions

View File

@@ -1,4 +1,4 @@
import { createClient, RedisClientType } from 'redis';
import { createClient } from 'redis';
import { ParkingGetterSetterRepository } from "./ParkingGetterSetterRepository";
import { IParkingStructure, IParkingStructureTimestampRecord } from "../entities/ParkingRepositoryEntities";
import { HistoricalParkingAverageQueryResult, ParkingStructureCountOptions } from "./ParkingGetterRepository";
@@ -10,6 +10,7 @@ export const PARKING_LOGGING_INTERVAL_MS = 600000;
export class RedisParkingRepository implements ParkingGetterSetterRepository {
private dataLastAdded: Map<ParkingStructureID, Date> = new Map();
private loggingIntervalMs = PARKING_LOGGING_INTERVAL_MS;
constructor(
private redisClient = createClient({
@@ -61,7 +62,7 @@ export class RedisParkingRepository implements ParkingGetterSetterRepository {
const lastAdded = this.dataLastAdded.get(structure.id);
const parkingLoggingIntervalExceeded = () => {
return !lastAdded || (now - lastAdded.getTime()) >= PARKING_LOGGING_INTERVAL_MS;
return !lastAdded || (now - lastAdded.getTime()) >= this.loggingIntervalMs;
};
if (parkingLoggingIntervalExceeded()) {
@@ -262,4 +263,8 @@ export class RedisParkingRepository implements ParkingGetterSetterRepository {
averageSpotsAvailable
};
};
setLoggingInterval = (intervalMs: number): void => {
this.loggingIntervalMs = intervalMs;
};
}