1
- const fs = require ( 'fs' ) ;
2
- const util = require ( 'util' ) ;
3
- const watch = require ( 'node-watch' ) ;
4
- const cron = require ( 'cron' ) ;
5
- const utils = require ( '../utils/utils' ) ;
6
- const AVLTree = require ( '../utils/avl-tree' ) ;
7
- const Logger = require ( '../utils/logger' ) ;
8
-
1
+ import fs from 'fs' ;
2
+ import util from 'util' ;
3
+ import watch from 'node-watch' ;
4
+ import { CronJob } from 'cron' ;
5
+ import { Utils } from '../utils/utils.js' ;
6
+ import { getLogger } from '../utils/logger.js' ;
7
+ import { AVLTree } from '../utils/avl-tree.js' ;
8
+
9
+ const utils = new Utils ( ) ;
9
10
const writeFile = util . promisify ( fs . writeFile ) ;
10
11
const readFile = util . promisify ( fs . readFile ) ;
11
- const logger = Logger . getLogger ( utils . serverConfig . logLevel || 'info' ) ;
12
+ const logger = getLogger ( utils . serverConfig . logLevel || 'info' ) ;
12
13
13
- class Connections {
14
+ export class Connections {
14
15
constructor ( options ) {
15
16
this . _agency = options [ 'agency' ] ;
16
17
this . _staticData = options [ 'staticData' ] ;
@@ -71,16 +72,17 @@ class Connections {
71
72
}
72
73
73
74
// Setup a cron job to recreate the tree every 10 minutes and shift its time window
74
- let recreateTree = new cron . CronJob ( {
75
- cronTime : '0 */10 * * * *' , // TODO: make this configurable
76
- onTick : ( ) => {
75
+ const recreateTree = new CronJob (
76
+ '0 */10 * * * *' , // TODO: make this configurable
77
+ ( ) => {
77
78
this . recreateJob . stop ( ) ;
78
79
if ( this . watcher ) this . watcher . close ( ) ;
79
80
logger . info ( `Recreating AVL tree for ${ this . agency } ...` ) ;
80
81
this . init ( ) ;
81
82
} ,
82
- start : true
83
- } ) ;
83
+ null ,
84
+ true
85
+ ) ;
84
86
85
87
this . recreateJob = recreateTree ;
86
88
} catch ( err ) {
@@ -207,6 +209,4 @@ class Connections {
207
209
set latestVersion ( newVersion ) {
208
210
this . _latestVersion = newVersion ;
209
211
}
210
- }
211
-
212
- module . exports = Connections ;
212
+ }
0 commit comments