|
@ -6,39 +6,17 @@
|
|
*/
|
|
*/
|
|
"use strict";
|
|
"use strict";
|
|
|
|
|
|
let TopicRepo = require('../../../repository/mysql/topics.repo');
|
|
|
|
let ModelUtil = require("../../../util/model.util.js");
|
|
|
|
let WlyySDK = require("../../../util/wlyy.sdk");
|
|
|
|
|
|
|
|
|
|
let onlineCache = require('../../socket.io/onlineCache').onlineCache();
|
|
let log = require("../../../util/log.js");
|
|
let log = require("../../../util/log.js");
|
|
let configFile = require('../../../include/commons').CONFIG_FILE;
|
|
let configFile = require('../../../include/commons').CONFIG_FILE;
|
|
let config = require('../../../resources/config/' + configFile);
|
|
let config = require('../../../resources/config/' + configFile);
|
|
|
|
|
|
const TOPIC_TTL = config.topicConfig.TTL;
|
|
|
|
|
|
|
|
class TopicTerminatingJob {
|
|
class TopicTerminatingJob {
|
|
constructor() {
|
|
constructor() {
|
|
}
|
|
}
|
|
|
|
|
|
static exec() {
|
|
static exec() {
|
|
TopicRepo.findAllBySessionLastActiveTime(TOPIC_TTL, function (err, topics) {
|
|
|
|
if (err) {
|
|
|
|
return ModelUtil.logError("Find topics without activity over " + TOPIC_TTL + " hour(s) failed", err);
|
|
|
|
}
|
|
|
|
|
|
|
|
topics.forEach(function (topic) {
|
|
|
|
let topicId = topic.topic_id;
|
|
|
|
let topicName = topic.topic_name;
|
|
|
|
|
|
|
|
WlyySDK.request('admin', '0a5c5258-8863-4b07-a3f9-88c768528ab4', '', 'admin_imei', '/doctor/consult/finish_consult?consult=' + topicId, 'GET', function (err, res) {
|
|
|
|
log.info("Got topic to terminate, " + topicId + ": " + topicName + ", last active time: " + topic.last_message_time);
|
|
|
|
|
|
|
|
if (err) return log.error("Terminating topic failed, try next time, error: ", err);
|
|
|
|
|
|
|
|
log.info("Terminating topic " + topicId + " succeed");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
onlineCache.init();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|