Commit 801e2564 authored by 智勇's avatar 智勇

修改为异步

parent 7a34c33c
......@@ -325,7 +325,8 @@ exports.db_sync_query = async function () {
}
let binlog_dir = '/home/quant_group/binlog2sql/binlog2sql'
// let binlog_dir = '/Users/zhiyong/IdeaProjects/github/binlog2sql/binlog2sql'
exports.binlog_to_sql = async function () {
await this.bindDefault
let req = this.request.body
......@@ -344,19 +345,6 @@ exports.binlog_to_sql = async function () {
if (time_range) {
endtime = new Date();
// if (time_range === 'Last 5 minutes') {
// starttime = new Date(endtime.getTime() - (1000 * 60 * 5))
// } else if (time_range === 'Last 15 minutes') {
// starttime = new Date(endtime.getTime() - (1000 * 60 * 15))
// } else if (time_range === 'Last 1 hour') {
// starttime = new Date(endtime.getTime() - (1000 * 60 * 60))
// } else if (time_range === 'Last 4 hours') {
// starttime = new Date(endtime.getTime() - (1000 * 60 * 60 * 4))
// } else if (time_range === 'Last 12 hours') {
// starttime = new Date(endtime.getTime() - (1000 * 60 * 60 * 12))
// } else if (time_range === 'Last 24 hours') {
// starttime = new Date(endtime.getTime() - (1000 * 60 * 60 * 24))
// }
switch (time_range) {
case 'Last 5 minutes':
starttime = new Date(endtime.getTime() - (1000 * 60 * 5))
......@@ -400,19 +388,48 @@ exports.binlog_to_sql = async function () {
binlog_file = binlog_file.split('\t')[0]
console.log(333, binlog_file)
let binlog_dir = '/home/quant_group/binlog2sql/binlog2sql'
// let binlog_dir = '/Users/zhiyong/IdeaProjects/github/binlog2sql/binlog2sql'
let log_file = (new Date()).getTime()
console.log(log_file)
console.log(`python ${binlog_dir}/binlog2sql.py -h${target_db_host} -P${target_db_port} -uqa -pqatest -d${db_name} -t ${tables} --start-file='${binlog_file}' --start-datetime='${starttime}' --stop-datetime='${endtime}'`)
let cmd = `python ${binlog_dir}/binlog2sql.py -h${target_db_host} -P${target_db_port} -uqa -pqatest -d${db_name} -t ${tables} --start-file='${binlog_file}' --start-datetime='${starttime}' --stop-datetime='${endtime}' > ${binlog_dir}/../logs/${log_file} `
console.log(cmd)
// 同步
let sql = String(execSync(`python ${binlog_dir}/binlog2sql.py -h${target_db_host} -P${target_db_port} -uqa -pqatest -d${db_name} -t ${tables} --start-file='${binlog_file}' --start-datetime='${starttime}' --stop-datetime='${endtime}'`))
console.log(sql)
this.body = { code: "0000", msg: sql }
//异步
cproc.exec(cmd, function (err, stdout, stderr) {
if (stderr) {
console.log('get error' + stderr)
this.body = { code: "0001", msg: "出错了" }
return
} else {
console.log(222, '--------binlog_to_sql complete')
// var data = JSON.parse(stdout)
// sql = sql + `pwd: python ${binlog_dir}/binlog2sql.py -h${target_db_host} -P${target_db_port} -uqa -pqatest -d${db_name} -t ${tables} --start-file='${binlog_file}' --start-datetime='${starttime}' --stop-datetime='${endtime}'`
}
})
this.body = { code: "0000", msg: { log_file: log_file, cmd: cmd } }
}
exports.binlog2sql_query = async function () {
await this.bindDefault
let req = this.request.body, sql
let log_file = req.log_file
let cmd = `ps -ef | grep ${log_file} | grep -v grep`
console.log(cmd)
try {
let _process = String(execSync(cmd))
// console.log(123, _process)
this.body = { code: "0001", msg: { sql: "请稍候~" } }
} catch (error) {
cmd = `cat ${binlog_dir}/../logs/${log_file}`
sql = String(execSync(cmd))
// console.log(sql)
this.body = { code: "0000", msg: { sql: sql, log_file: log_file } }
}
}
exports.get_time_range = async function () {
await this.bindDefault();
this.body = ['Last 5 minutes', 'Last 15 minutes', 'Last 1 hour', 'Last 4 hours', 'Last 12 hours', 'Last 24 hours',]
this.body = ['', 'Last 5 minutes', 'Last 15 minutes', 'Last 1 hour', 'Last 4 hours', 'Last 12 hours', 'Last 24 hours',]
return
}
\ No newline at end of file
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