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

@@ -17,6 +17,7 @@ export const MAX_NUM_ENTRIES = 2016;
export class InMemoryParkingRepository implements ParkingGetterSetterRepository {
private dataLastAdded: Map<ParkingStructureID, Date> = new Map();
private loggingIntervalMs = PARKING_LOGGING_INTERVAL_MS;
constructor(
private structures: Map<ParkingStructureID, IParkingStructure> = new Map(),
@@ -33,9 +34,9 @@ export class InMemoryParkingRepository implements ParkingGetterSetterRepository
const now = Date.now();
const lastAdded = this.dataLastAdded.get(structure.id);
function parkingLoggingIntervalExceeded() {
return !lastAdded || (now - lastAdded.getTime()) >= PARKING_LOGGING_INTERVAL_MS;
}
const parkingLoggingIntervalExceeded = () => {
return !lastAdded || (now - lastAdded.getTime()) >= this.loggingIntervalMs;
};
if (parkingLoggingIntervalExceeded()) {
const timestampRecord: IParkingStructureTimestampRecord = {
@@ -131,4 +132,8 @@ export class InMemoryParkingRepository implements ParkingGetterSetterRepository
averageSpotsAvailable
};
};
setLoggingInterval = (intervalMs: number): void => {
this.loggingIntervalMs = intervalMs;
};
}

View File

@@ -7,4 +7,6 @@ export interface ParkingGetterSetterRepository extends ParkingGetterRepository {
removeParkingStructureIfExists(id: string): Promise<IParkingStructure | null>;
clearParkingStructureData(): Promise<void>;
setLoggingInterval(intervalMs: number): void;
}

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;
};
}