|
|
|
@ -28,6 +28,8 @@ class HeroUnion {
@@ -28,6 +28,8 @@ class HeroUnion {
|
|
|
|
|
|
|
|
|
|
//构造函数,设置默认配置
|
|
|
|
|
constructor() { |
|
|
|
|
this.config = null; |
|
|
|
|
|
|
|
|
|
//this.task_data_dir = path.resolve('./tmp/data/'); //任务数据保存目录
|
|
|
|
|
this.task_cache_time = 86400; //任务数据最长缓存时间,单位:秒
|
|
|
|
|
this.task_data_max_size = 1024; //任务数据最大字节数,单位:KB
|
|
|
|
@ -73,6 +75,14 @@ class HeroUnion {
@@ -73,6 +75,14 @@ class HeroUnion {
|
|
|
|
|
return JSON.stringify(data).length > this.task_data_max_size * 1024; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async getConfig(forceReload) { |
|
|
|
|
if ( !this.config || (typeof(forceReload) != 'undefined' && forceReload) ) { |
|
|
|
|
this.config = await common.getConfigFromJsonFile('config.json'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return this.config; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//--任务相关功能--
|
|
|
|
|
|
|
|
|
|
//根据任务提交者ID和时间戳生成任务ID编号
|
|
|
|
@ -213,9 +223,10 @@ class HeroUnion {
@@ -213,9 +223,10 @@ class HeroUnion {
|
|
|
|
|
return this.tasks.find((item) => item.id == id); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//TODO: 根据uuid获取用户的签名密钥
|
|
|
|
|
getUserToken(uuid) { |
|
|
|
|
return 'token'; |
|
|
|
|
//根据uuid获取用户的签名密钥
|
|
|
|
|
async getUserToken(uuid) { |
|
|
|
|
let config = await this.getConfig(); |
|
|
|
|
return config && typeof(config.tokens[uuid]) != 'undefined' ? config.tokens[uuid] : ''; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//任务完成触发回调通知
|
|
|
|
@ -232,17 +243,18 @@ class HeroUnion {
@@ -232,17 +243,18 @@ class HeroUnion {
|
|
|
|
|
"task_result": task.results, |
|
|
|
|
"timestamp": this.getTimestamp(), |
|
|
|
|
}; |
|
|
|
|
params.sign = common.sign(params, this.getUserToken(task.uuid)); |
|
|
|
|
let token = await this.getUserToken(task.uuid); |
|
|
|
|
params.sign = common.sign(params, token); |
|
|
|
|
const response = await axios.post(notify_url, params, {timeout: this.notify_timeout*1000}); |
|
|
|
|
if (response.status == 200) { |
|
|
|
|
notified = true; |
|
|
|
|
}else { |
|
|
|
|
console.error('Notify to %s failed, response status: %s, status text: %s, result: %s', |
|
|
|
|
console.error('[FAILED] Notify to %s failed, response status: %s, status text: %s, result: %s', |
|
|
|
|
notify_url, response.status, response.statusText, response.daa); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}catch(err) { |
|
|
|
|
console.error('Notify to %s failed: %s', notify_url, err); |
|
|
|
|
console.error('[ERROR] Notify to %s failed: %s', notify_url, err); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return notified; |
|
|
|
|