@@ -92,9 +92,6 @@ var handleMerges = function(db, callback) {
92
92
//update new user
93
93
94
94
db . collection ( 'app_users' + app_id ) . update ( { _id : newAppUser . _id } , { '$set' : newAppUser } , function ( err6 ) {
95
- if ( callback && typeof callback === 'function' ) {
96
- callback ( null , newAppUser ) ; //we do not return error as merge is already registred. Doc merging will be retried in job.
97
- }
98
95
//Dispatch to other plugins only after callback.
99
96
if ( ! err6 ) {
100
97
//update metric changes document
@@ -113,6 +110,9 @@ var handleMerges = function(db, callback) {
113
110
}
114
111
} ) ;
115
112
}
113
+ else {
114
+ resolve ( ) ; //will retry after
115
+ }
116
116
} ) ;
117
117
} ) ;
118
118
} ) ;
@@ -170,11 +170,38 @@ class UserMergeJob extends job.Job {
170
170
* Run the job
171
171
* @param {Db } db connection
172
172
* @param {done } done callback
173
+ * @param {function } progressJob - callback when progress made
173
174
*/
174
- run ( db , done ) {
175
+ run ( db , done , progressJob ) {
176
+ var total = 0 ;
177
+ var current = 0 ;
178
+ var bookmark = "" ;
179
+
180
+ /**
181
+ * check job status periodically
182
+ */
183
+ function ping ( ) {
184
+ log . d ( 'Pinging user merging job' ) ;
185
+ if ( timeout ) {
186
+ progressJob ( total , current , bookmark ) ;
187
+ timeout = setTimeout ( ping , 10000 ) ;
188
+ }
189
+ }
190
+ /**
191
+ * end job
192
+ * @returns {varies } job done
193
+ */
194
+ function endJob ( ) {
195
+ log . d ( 'Ending user merging job' ) ;
196
+ clearTimeout ( timeout ) ;
197
+ timeout = 0 ;
198
+ return done ( ) ;
199
+ }
200
+ var timeout = setTimeout ( ping , 10000 ) ;
201
+
175
202
log . d ( 'finishing up not finished merges merges...' ) ;
176
203
handleMerges ( db , ( ) => {
177
- done ( ) ;
204
+ endJob ( ) ;
178
205
} ) ;
179
206
}
180
207
}
0 commit comments