Commit 4085d98c authored by 姜登's avatar 姜登

gjj

parent 993cb511
Pipeline #3981 passed with stage
in 4 seconds
......@@ -15,6 +15,7 @@ class ScriptsService extends Service {
this.fetchHelpUrl = scriptsAPI.fetchHelpUrl;
this.redisScriptsKey = scriptsAPI.redisScriptsKey;
this.redisParamsKey = scriptsAPI.redisParamsKey;
this.redisScriptListKey = scriptsAPI.redisScriptListKey;
}
async fetchScripts() {
......@@ -42,13 +43,25 @@ class ScriptsService extends Service {
return result.data;
}
async fetchOneScripts(scriptId) {
const { baseURL, fetchOneScriptUrl, ctx } = this;
const { baseURL, fetchOneScriptUrl, redisScriptListKey, ctx } = this;
const data = await this.app.cache.get(redisScriptListKey + scriptId);
if (data) {
try {
return JSON.parse(data);
} catch (err) {
ctx.logger.error('【Scripts】fetchOneScriptsFromRedis', 'result:', data, err);
await this.app.cache.del(redisScriptListKey + scriptId);
}
}
const result = await ctx.curl(baseURL + fetchOneScriptUrl + '/' + scriptId, {
charset: 'utf-8',
timeout: ['30s', '30s'],
dataType: 'json',
contentType: 'json',
});
if (result.data && (String(result.data.id) === scriptId)) {
await this.app.cache.set(redisScriptListKey + scriptId, JSON.stringify(result.data), 60);
}
return result.data;
}
......@@ -162,7 +175,7 @@ class ScriptsService extends Service {
async fetchScriptName(scriptId) {
try {
const city = await this.fetchOneScripts(scriptId);
return city.name;
return city.name || '未知';
} catch (err) {
return '未知';
}
......
......@@ -45,6 +45,7 @@ module.exports = () => {
fetchScriptByCityNameUrl: '/chaos/hf/city_scripts',
redisScriptsKey: 'URANUS.HF.SCRIPTS',
redisParamsKey: 'URANUS.HF.PARAMS',
redisScriptListKey:'URANUS.HF.SCRIPTLIST',
};
config.storageAPI = {
......
......@@ -38,6 +38,7 @@ module.exports = () => {
fetchScriptByCityNameUrl: '/chaos/hf/city_scripts',
redisScriptsKey: 'URANUS.HF.SCRIPTS',
redisParamsKey: 'URANUS.HF.PARAMS',
redisScriptListKey:'URANUS.HF.SCRIPTLIST',
};
config.storageAPI = {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment