blob: 211210df0fc11932628ef0d3d5df4168c158dc6a [file] [log] [blame]
Adrià Vilanova Martínez43c75202024-10-19 15:55:15 +02001import NodeWatcherSingleton, { NodeWatcherAdapter } from '../../../../infrastructure/presentation/nodeWatcher/NodeWatcher.adapter';
Adrià Vilanova Martínez18d03c42024-04-21 16:43:01 +02002import { ConcreteNodeWatcherScriptHandler } from './handlers/NodeWatcherScriptHandler';
3import Script from '../Script';
4
Adrià Vilanova Martínez8b591d92024-10-19 15:55:15 +02005/**
6 * @deprecated
7 */
8export default abstract class LegacyNodeWatcherScript<Options> extends Script {
Adrià Vilanova Martínez18d03c42024-04-21 16:43:01 +02009 public abstract handlers: Map<
10 string,
11 ConcreteNodeWatcherScriptHandler<Options>
12 >;
13
Adrià Vilanova Martínez43c75202024-10-19 15:55:15 +020014 private nodeWatcher: NodeWatcherAdapter;
15
16 constructor() {
17 super();
18
19 // TODO(https://iavm.xyz/b/226): Retrieve this via constructor injection.
20 this.nodeWatcher = NodeWatcherSingleton.getInstance();
21 }
22
Adrià Vilanova Martínez18d03c42024-04-21 16:43:01 +020023 /**
24 * Resolves to the options when the script is executed.
25 *
Adrià Vilanova Martínez18d03c42024-04-21 16:43:01 +020026 */
27 protected abstract optionsFactory(): Options;
28
29 execute() {
Adrià Vilanova Martínez18d03c42024-04-21 16:43:01 +020030 const options = this.optionsFactory();
31
Adrià Vilanova Martínez43c75202024-10-19 15:55:15 +020032 this.nodeWatcher.start();
Adrià Vilanova Martínez18d03c42024-04-21 16:43:01 +020033 for (const [key, handlerClass] of this.handlers) {
34 const handler = new handlerClass(options);
Adrià Vilanova Martínez43c75202024-10-19 15:55:15 +020035 this.nodeWatcher.setHandler(key, handler);
Adrià Vilanova Martínez18d03c42024-04-21 16:43:01 +020036 }
37 }
38}