update timed loader to use class composition

This commit is contained in:
2025-04-11 16:52:27 -07:00
parent d1a47baea6
commit a0e0c19ca3
3 changed files with 35 additions and 38 deletions

View File

@@ -1,6 +1,5 @@
import { ShuttleRepositoryLoader } from "../loaders/ShuttleRepositoryLoader";
import { ETANotificationScheduler } from "../notifications/schedulers/ETANotificationScheduler";
import { TimedApiBasedShuttleRepositoryLoader } from "../loaders/TimedApiBasedShuttleRepositoryLoader";
import { TimedApiBasedRepositoryLoader } from "../loaders/TimedApiBasedRepositoryLoader";
import { UnoptimizedInMemoryShuttleRepository } from "../repositories/UnoptimizedInMemoryShuttleRepository";
import { RedisNotificationRepository } from "../repositories/RedisNotificationRepository";
import { NotificationRepository } from "../repositories/NotificationRepository";
@@ -27,7 +26,7 @@ export class InterchangeSystem {
constructor(
public name: string,
public id: string,
public shuttleDataLoader: ShuttleRepositoryLoader,
public shuttleTimedDataLoader: TimedApiBasedRepositoryLoader,
public shuttleRepository: ShuttleGetterSetterRepository,
public notificationScheduler: ETANotificationScheduler,
public notificationRepository: NotificationRepository,
@@ -43,12 +42,15 @@ export class InterchangeSystem {
args: InterchangeSystemBuilderArguments,
) {
const shuttleRepository = new UnoptimizedInMemoryShuttleRepository();
const shuttleDataLoader = new TimedApiBasedShuttleRepositoryLoader(
const shuttleDataLoader = new ApiBasedShuttleRepositoryLoader(
args.passioSystemId,
args.id,
shuttleRepository
);
await shuttleDataLoader.start();
const timedShuttleDataLoader = new TimedApiBasedRepositoryLoader(
shuttleDataLoader,
);
await timedShuttleDataLoader.start();
const notificationRepository = new RedisNotificationRepository();
await notificationRepository.connect();
@@ -62,7 +64,7 @@ export class InterchangeSystem {
return new InterchangeSystem(
args.name,
args.id,
shuttleDataLoader,
timedShuttleDataLoader,
shuttleRepository,
notificationScheduler,
notificationRepository,
@@ -84,6 +86,11 @@ export class InterchangeSystem {
args.id,
shuttleRepository
);
// Note that this loader should not be started,
// so the test data doesn't get overwritten
const timedShuttleLoader = new TimedApiBasedRepositoryLoader(
shuttleDataLoader,
);
const notificationRepository = new InMemoryNotificationRepository();
const notificationScheduler = new ETANotificationScheduler(
@@ -96,7 +103,7 @@ export class InterchangeSystem {
return new InterchangeSystem(
args.name,
args.id,
shuttleDataLoader,
timedShuttleLoader,
shuttleRepository,
notificationScheduler,
notificationRepository,