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 { ...@@ -15,6 +15,7 @@ class ScriptsService extends Service {
this.fetchHelpUrl = scriptsAPI.fetchHelpUrl; this.fetchHelpUrl = scriptsAPI.fetchHelpUrl;
this.redisScriptsKey = scriptsAPI.redisScriptsKey; this.redisScriptsKey = scriptsAPI.redisScriptsKey;
this.redisParamsKey = scriptsAPI.redisParamsKey; this.redisParamsKey = scriptsAPI.redisParamsKey;
this.redisScriptListKey = scriptsAPI.redisScriptListKey;
} }
async fetchScripts() { async fetchScripts() {
...@@ -42,13 +43,25 @@ class ScriptsService extends Service { ...@@ -42,13 +43,25 @@ class ScriptsService extends Service {
return result.data; return result.data;
} }
async fetchOneScripts(scriptId) { 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, { const result = await ctx.curl(baseURL + fetchOneScriptUrl + '/' + scriptId, {
charset: 'utf-8', charset: 'utf-8',
timeout: ['30s', '30s'], timeout: ['30s', '30s'],
dataType: 'json', dataType: 'json',
contentType: '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; return result.data;
} }
...@@ -162,7 +175,7 @@ class ScriptsService extends Service { ...@@ -162,7 +175,7 @@ class ScriptsService extends Service {
async fetchScriptName(scriptId) { async fetchScriptName(scriptId) {
try { try {
const city = await this.fetchOneScripts(scriptId); const city = await this.fetchOneScripts(scriptId);
return city.name; return city.name || '未知';
} catch (err) { } catch (err) {
return '未知'; return '未知';
} }
......
...@@ -45,6 +45,7 @@ module.exports = () => { ...@@ -45,6 +45,7 @@ module.exports = () => {
fetchScriptByCityNameUrl: '/chaos/hf/city_scripts', fetchScriptByCityNameUrl: '/chaos/hf/city_scripts',
redisScriptsKey: 'URANUS.HF.SCRIPTS', redisScriptsKey: 'URANUS.HF.SCRIPTS',
redisParamsKey: 'URANUS.HF.PARAMS', redisParamsKey: 'URANUS.HF.PARAMS',
redisScriptListKey:'URANUS.HF.SCRIPTLIST',
}; };
config.storageAPI = { config.storageAPI = {
......
...@@ -38,6 +38,7 @@ module.exports = () => { ...@@ -38,6 +38,7 @@ module.exports = () => {
fetchScriptByCityNameUrl: '/chaos/hf/city_scripts', fetchScriptByCityNameUrl: '/chaos/hf/city_scripts',
redisScriptsKey: 'URANUS.HF.SCRIPTS', redisScriptsKey: 'URANUS.HF.SCRIPTS',
redisParamsKey: 'URANUS.HF.PARAMS', redisParamsKey: 'URANUS.HF.PARAMS',
redisScriptListKey:'URANUS.HF.SCRIPTLIST',
}; };
config.storageAPI = { 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