-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ts
56 lines (49 loc) · 1.57 KB
/
main.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
* Created with @iobroker/create-adapter v2.1.1
*/
// The adapter-core module gives you access to the core ioBroker functions
// you need to create an adapter
import * as utils from '@iobroker/adapter-core';
import bootstrap from './nestjs/main';
// Load your modules here, e.g.:
// import * as fs from "fs";
class Nestjs extends utils.Adapter {
public constructor(options: Partial<utils.AdapterOptions> = {}) {
super({
...options,
name: 'nestjs',
});
this.on('ready', this.onReady.bind(this));
this.on('unload', this.onUnload.bind(this));
}
/**
* Is called when databases are connected and adapter received configuration.
*/
private async onReady(): Promise<void> {
this.log.warn('onReady1');
bootstrap(this);
this.log.warn('onReady1');
}
/**
* Is called when adapter shuts down - callback has to be called under any circumstances!
*/
private onUnload(callback: () => void): void {
try {
// Here you must clear all timeouts or intervals that may still be active
// clearTimeout(timeout1);
// clearTimeout(timeout2);
// ...
// clearInterval(interval1);
callback();
} catch (e) {
callback();
}
}
}
if (require.main !== module) {
// Export the constructor in compact mode
module.exports = (options: Partial<utils.AdapterOptions> | undefined) => new Nestjs(options);
} else {
// otherwise start the instance directly
(() => new Nestjs())();
}