@@ -14,11 +14,14 @@ const { Logger } = require('./utilities');
1414const database = require ( './database' ) ;
1515const { webUiServer } = require ( './server' ) ;
1616const { gRPCServer } = require ( './server/index.js' ) ;
17- const { GRPCConfig } = require ( './config' ) ;
17+ const { GRPCConfig, ServicesConfig } = require ( './config' ) ;
18+
19+ const { monalisa : monalisaConfig } = ServicesConfig ;
1820const { handleLostRunsAndEnvironments } = require ( './server/services/housekeeping/handleLostRunsAndEnvironments.js' ) ;
19- const { ServicesConfig } = require ( './config/index.js' ) ;
2021const { isInTestMode } = require ( './utilities/env-utils.js' ) ;
2122const { ScheduledProcessesManager } = require ( './server/services/ScheduledProcessesManager.js' ) ;
23+ const { MonALISASynchronizer } = require ( './server/monalisa-synchronization/MonALISASynchronizer' ) ;
24+ const { createMonALISAClient } = require ( './server/monalisa-synchronization/MonALISAClient' ) ;
2225
2326/**
2427 * Bookkeeping Application
@@ -52,26 +55,20 @@ class BookkeepingApplication {
5255 await this . gRPCServer . listen ( gRPCOrigin ) ;
5356 }
5457
55- if ( ServicesConfig . enableHousekeeping ) {
58+ if ( monalisaConfig . enableSynchronization ) {
59+ const monALISASynchronizer = await this . createMonALISASynchronizer ( ) ;
5660 this . scheduledProcessesManager . schedule (
57- async ( ) => {
58- try {
59- const { transitionedEnvironments, endedRuns } = await handleLostRunsAndEnvironments ( ) ;
60- const subMessages = [ ] ;
61- if ( transitionedEnvironments . length > 0 ) {
62- subMessages . push ( `environments (${ transitionedEnvironments . join ( ', ' ) } )` ) ;
63- }
64- if ( endedRuns . length > 0 ) {
65- subMessages . push ( `runs (${ endedRuns . join ( ', ' ) } )` ) ;
66- }
67-
68- if ( subMessages . length > 0 ) {
69- this . logger . debug ( `Updated lost ${ subMessages . join ( ' and ' ) } ` ) ;
70- }
71- } catch ( error ) {
72- this . logger . error ( `Error while handling lost runs & environments: ${ error } ` ) ;
73- }
61+ ( ) => monALISASynchronizer . synchronizeDataPassesFromMonALISA ( ) ,
62+ {
63+ wait : 10 * 1000 ,
64+ every : monalisaConfig . synchronizationPeriod ,
7465 } ,
66+ ) ;
67+ }
68+
69+ if ( ServicesConfig . enableHousekeeping ) {
70+ this . scheduledProcessesManager . schedule (
71+ ( ) => this . housekeeping ( ) ,
7572 {
7673 wait : 30 * 1000 ,
7774 every : 30 * 1000 ,
@@ -86,6 +83,43 @@ class BookkeepingApplication {
8683 this . logger . info ( 'Started' ) ;
8784 }
8885
86+ /**
87+ * Instantiate MonALISA synchronizer with global configuration
88+ * @return {MonALISASynchronizer } instance
89+ */
90+ async createMonALISASynchronizer ( ) {
91+ return new MonALISASynchronizer ( await createMonALISAClient ( {
92+ dataPassesUrl : monalisaConfig . dataPassesUrl ,
93+ dataPassDetailsUrl : monalisaConfig . dataPassDetailsUrl ,
94+ yearLowerLimit : monalisaConfig . dataPassesYearLowerLimit ,
95+ userCertificatePath : monalisaConfig . userCertificate . path ,
96+ certificatePassphrase : monalisaConfig . userCertificate . passphrase ,
97+ } ) ) ;
98+ }
99+
100+ /**
101+ * Houskeeping method, it wraps @see handleLostRunsAndEnvironments and logs its results
102+ * @return {Promise<void> } promise
103+ */
104+ async housekeeping ( ) {
105+ try {
106+ const { transitionedEnvironments, endedRuns } = await handleLostRunsAndEnvironments ( ) ;
107+ const subMessages = [ ] ;
108+ if ( transitionedEnvironments . length > 0 ) {
109+ subMessages . push ( `environments (${ transitionedEnvironments . join ( ', ' ) } )` ) ;
110+ }
111+ if ( endedRuns . length > 0 ) {
112+ subMessages . push ( `runs (${ endedRuns . join ( ', ' ) } )` ) ;
113+ }
114+
115+ if ( subMessages . length > 0 ) {
116+ this . logger . debug ( `Updated lost ${ subMessages . join ( ' and ' ) } ` ) ;
117+ }
118+ } catch ( error ) {
119+ this . logger . error ( `Error while handling lost runs & environments: ${ error } ` ) ;
120+ }
121+ }
122+
89123 /**
90124 * Begins the process of terminating the application. Calling this method terminates the process.
91125 *
0 commit comments