Skip to content

Commit 9df3145

Browse files
committedSep 8, 2018
fix chosenman
1 parent 6b58d00 commit 9df3145

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed
 

‎core/services/client-manager.js

+17-8
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ proto.updateCheckFromCache = function(deploymentKey, appVersion, label, packageH
7474
.finally(() => client.quit());
7575
}
7676

77-
proto.getChosenManCacheKey = function(deploymentKey, appVersion, clientUniqueId, rollout) {
78-
return [CHOSEN_MAN, deploymentKey, appVersion, clientUniqueId, rollout].join(':');
77+
proto.getChosenManCacheKey = function(packageId, rollout, clientUniqueId) {
78+
return [CHOSEN_MAN, packageId, rollout, clientUniqueId].join(':');
7979
}
8080

8181
proto.random = function(rollout) {
@@ -87,7 +87,7 @@ proto.random = function(rollout) {
8787
}
8888
}
8989

90-
proto.chosenMan = function (rollout, deploymentKey, appVersion, clientUniqueId) {
90+
proto.chosenMan = function (packageId, rollout, clientUniqueId) {
9191
var self = this;
9292
if (rollout >= 100) {
9393
return Promise.resolve(true);
@@ -97,7 +97,7 @@ proto.chosenMan = function (rollout, deploymentKey, appVersion, clientUniqueId)
9797
return self.random(rollout);
9898
} else {
9999
var client = factory.getRedisClient("default");
100-
var redisCacheKey = self.getChosenManCacheKey(deploymentKey, appVersion, clientUniqueId, rollout);
100+
var redisCacheKey = self.getChosenManCacheKey(packageId, rollout, clientUniqueId);
101101
return client.getAsync(redisCacheKey)
102102
.then((data) => {
103103
if (data == 1) {
@@ -120,6 +120,7 @@ proto.chosenMan = function (rollout, deploymentKey, appVersion, clientUniqueId)
120120

121121
proto.updateCheck = function(deploymentKey, appVersion, label, packageHash, clientUniqueId) {
122122
var rs = {
123+
packageId: 0,
123124
downloadURL: "",
124125
downloadUrl: "",
125126
description: "",
@@ -176,6 +177,7 @@ proto.updateCheck = function(deploymentKey, appVersion, label, packageHash, clie
176177
if (packages
177178
&& _.eq(packages.deployment_id, deploymentsVersions.deployment_id)
178179
&& !_.eq(packages.package_hash, packageHash)) {
180+
rs.packageId = packageId;
179181
rs.downloadUrl = rs.downloadURL = common.getBlobDownloadUrl(_.get(packages, 'blob_url'));
180182
rs.description = _.get(packages, 'description', '');
181183
rs.isAvailable = _.eq(packages.is_disabled, 1) ? false : true;
@@ -248,14 +250,21 @@ proto.reportStatusDeploy = function (deploymentKey, label, clientUniqueId, other
248250
var constConfig = require('../const');
249251
var status = _.get(others, "status");
250252
var packageId = packages.id;
253+
var previous_deployment_key = _.get(others, 'previousDeploymentKey');
254+
var previous_label = _.get(others, 'previousLabelOrAppVersion');
251255
if (_.eq(status, "DeploymentSucceeded")) {
252256
return Promise.all([
253257
models.LogReportDeploy.create({
254258
package_id: packageId,
255259
client_unique_id: clientUniqueId,
256-
previous_label: _.get(others, 'previousLabelOrAppVersion'),
257-
previous_deployment_key: _.get(others, 'previousDeploymentKey'),
260+
previous_label: previous_label,
261+
previous_deployment_key: previous_deployment_key,
258262
status: constConfig.DEPLOYMENT_SUCCEEDED
263+
})
264+
.then(() => {
265+
if (previous_deployment_key && previous_label) {
266+
267+
}
259268
}),
260269
models.PackagesMetrics.addOneOnInstalledById(packageId),
261270
models.PackagesMetrics.addOneOnActiveById(packageId),
@@ -265,8 +274,8 @@ proto.reportStatusDeploy = function (deploymentKey, label, clientUniqueId, other
265274
models.LogReportDeploy.create({
266275
package_id: packageId,
267276
client_unique_id: clientUniqueId,
268-
previous_label: _.get(others, 'previousLabelOrAppVersion'),
269-
previous_deployment_key: _.get(others, 'previousDeploymentKey'),
277+
previous_label: previous_label,
278+
previous_deployment_key: previous_deployment_key,
270279
status: constConfig.DEPLOYMENT_FAILED
271280
}),
272281
models.PackagesMetrics.addOneOnInstalledById(packageId),

‎routes/index.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,17 @@ router.get('/updateCheck', (req, res, next) => {
4747
clientManager.updateCheckFromCache(deploymentKey, appVersion, label, packageHash, clientUniqueId)
4848
.then((rs) => {
4949
//灰度检测
50-
return clientManager.chosenMan(rs.rollout, deploymentKey, appVersion, clientUniqueId)
50+
return clientManager.chosenMan(rs.packageId, rs.rollout, clientUniqueId)
5151
.then((data)=>{
52-
if (!data) {
53-
rs.isAvailable = false;
54-
return rs;
55-
}
52+
if (!data) {
53+
rs.isAvailable = false;
5654
return rs;
55+
}
56+
return rs;
5757
});
5858
})
5959
.then((rs) => {
60+
delete rs.packageId;
6061
delete rs.rollout;
6162
res.send({"updateInfo":rs});
6263
})

0 commit comments

Comments
 (0)