mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-19 08:50:29 +00:00
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:
@@ -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;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user