@@ -235,7 +235,13 @@ proto.reportStatusDownload = function(deploymentKey, label, clientUniqueId) {
235
235
return this . getPackagesInfo ( deploymentKey , label )
236
236
. then ( ( packages ) => {
237
237
return Promise . all ( [
238
- models . PackagesMetrics . addOneOnDownloadById ( packages . id ) ,
238
+ models . PackagesMetrics . findOne ( { where : { package_id : packages . id } } )
239
+ . then ( ( metrics ) => {
240
+ if ( metrics ) {
241
+ return metrics . increment ( 'downloaded' ) ;
242
+ }
243
+ return ;
244
+ } ) ,
239
245
models . LogReportDownload . create ( {
240
246
package_id : packages . id ,
241
247
client_unique_id : clientUniqueId
@@ -248,40 +254,62 @@ proto.reportStatusDeploy = function (deploymentKey, label, clientUniqueId, other
248
254
return this . getPackagesInfo ( deploymentKey , label )
249
255
. then ( ( packages ) => {
250
256
var constConfig = require ( '../const' ) ;
251
- var status = _ . get ( others , "status" ) ;
257
+ var statusText = _ . get ( others , "status" ) ;
258
+ var status = 0 ;
259
+ if ( _ . eq ( statusText , "DeploymentSucceeded" ) ) {
260
+ status = constConfig . DEPLOYMENT_SUCCEEDED ;
261
+ } else if ( _ . eq ( statusText , "DeploymentFailed" ) ) {
262
+ status = constConfig . DEPLOYMENT_FAILED ;
263
+ }
252
264
var packageId = packages . id ;
253
265
var previous_deployment_key = _ . get ( others , 'previousDeploymentKey' ) ;
254
266
var previous_label = _ . get ( others , 'previousLabelOrAppVersion' ) ;
255
- if ( _ . eq ( status , "DeploymentSucceeded" ) ) {
256
- return Promise . all ( [
257
- models . LogReportDeploy . create ( {
258
- package_id : packageId ,
259
- client_unique_id : clientUniqueId ,
260
- previous_label : previous_label ,
261
- previous_deployment_key : previous_deployment_key ,
262
- status : constConfig . DEPLOYMENT_SUCCEEDED
263
- } )
264
- . then ( ( ) => {
265
- if ( previous_deployment_key && previous_label ) {
266
-
267
- }
268
- } ) ,
269
- models . PackagesMetrics . addOneOnInstalledById ( packageId ) ,
270
- models . PackagesMetrics . addOneOnActiveById ( packageId ) ,
271
- ] ) ;
272
- } else if ( _ . eq ( status , "DeploymentFailed" ) ) {
267
+ if ( status > 0 ) {
273
268
return Promise . all ( [
274
269
models . LogReportDeploy . create ( {
275
270
package_id : packageId ,
276
271
client_unique_id : clientUniqueId ,
277
272
previous_label : previous_label ,
278
273
previous_deployment_key : previous_deployment_key ,
279
- status : constConfig . DEPLOYMENT_FAILED
274
+ status : status
280
275
} ) ,
281
- models . PackagesMetrics . addOneOnInstalledById ( packageId ) ,
282
- models . PackagesMetrics . addOneOnFailedById ( packageId ) ,
283
- ] ) ;
284
- } else {
276
+ models . PackagesMetrics . findOne ( { where : { package_id : packageId } } )
277
+ . then ( ( metrics ) => {
278
+ if ( _ . isEmpty ( metrics ) ) {
279
+ return ;
280
+ }
281
+ if ( constConfig . DEPLOYMENT_SUCCEEDED ) {
282
+ return metrics . increment ( [ 'installed' , 'active' ] , { by : 1 } ) ;
283
+ } else {
284
+ return metrics . increment ( [ 'installed' , 'failed' ] , { by : 1 } ) ;
285
+ }
286
+ } )
287
+ ] )
288
+ . then ( ( ) => {
289
+ if ( previous_deployment_key && previous_label ) {
290
+ return models . Deployments . findOne ( { where : { deployment_key : previous_deployment_key } } )
291
+ . then ( ( dep ) => {
292
+ if ( _ . isEmpty ( dep ) ) {
293
+ return ;
294
+ }
295
+ return models . Packages . findOne ( { where : { deployment_id : dep . id , label : previous_label } } )
296
+ . then ( ( p ) => {
297
+ if ( _ . isEmpty ( p ) ) {
298
+ return ;
299
+ }
300
+ return models . PackagesMetrics . findOne ( { where :{ package_id : p . id } } ) ;
301
+ } ) ;
302
+ } )
303
+ . then ( ( metrics ) => {
304
+ if ( metrics ) {
305
+ return metrics . decrement ( 'active' ) ;
306
+ }
307
+ return ;
308
+ } ) ;
309
+ }
310
+ return ;
311
+ } ) ;
312
+ } else {
285
313
return ;
286
314
}
287
315
} ) ;
0 commit comments