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