mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +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:
@@ -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;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -7,4 +7,6 @@ export interface ParkingGetterSetterRepository extends ParkingGetterRepository {
|
||||
removeParkingStructureIfExists(id: string): Promise<IParkingStructure | null>;
|
||||
|
||||
clearParkingStructureData(): Promise<void>;
|
||||
|
||||
setLoggingInterval(intervalMs: number): void;
|
||||
}
|
||||
|
||||
@@ -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