@@ -35,13 +35,14 @@ class Notificator {
35
35
* @param {Object } options
36
36
*/
37
37
38
- constructor ( { name, fs_context, connect_files_dir, nc_config_fs} ) {
38
+ constructor ( { name, fs_context, connect_files_dir, nc_config_fs, batch_size } ) {
39
39
this . name = name ;
40
40
this . connect_str_to_connection = new Map ( ) ;
41
41
this . notif_to_connect = new Map ( ) ;
42
42
this . fs_context = fs_context ?? get_process_fs_context ( ) ;
43
43
this . connect_files_dir = connect_files_dir ?? DEFAULT_CONNECT_FILES_DIR ;
44
44
this . nc_config_fs = nc_config_fs ;
45
+ this . batch_size = batch_size || config . NOTIFICATION_BATCH || 10 ;
45
46
}
46
47
47
48
async run_batch ( ) {
@@ -112,7 +113,7 @@ class Notificator {
112
113
*/
113
114
async _notify ( fs_context , log_file , failure_append ) {
114
115
const file = new LogFile ( fs_context , log_file ) ;
115
- const send_promises = [ ] ;
116
+ let send_promises = [ ] ;
116
117
await file . collect_and_process ( async str => {
117
118
try {
118
119
const notif = JSON . parse ( str ) ;
@@ -137,6 +138,10 @@ class Notificator {
137
138
}
138
139
const send_promise = connection . promise_notify ( notif , failure_append ) ;
139
140
if ( send_promise ) send_promises . push ( send_promise ) ;
141
+ if ( send_promises . length > this . batch_size ) {
142
+ await Promise . all ( send_promises ) ;
143
+ send_promises = [ ] ;
144
+ }
140
145
} catch ( err ) {
141
146
dbg . error ( "Failed to notify. err = " , err , ", str =" , str ) ;
142
147
await failure_append ( str ) ;
0 commit comments