Commit ceb8c3b6 authored by 智勇's avatar 智勇

同步latest库

parent 98b4917c
......@@ -7,22 +7,29 @@ const getClient = require('../resource/getClient')
const awaitRequest = require('../utils/awaitRequest')
const sleep = require('../utils/sleep')
const APP_CONFIG = require('../config')
const dingTalk = require('../utils/dingTalk')
const syncDB = async (cluster) => {
logger.info('dailySyncDB start')
const client = (await getClient(cluster)).clientInfo
const ns = await getAllNamespace(client)
const summary = {}
// // for test
// const testNamespace = ['fis']
// const testNamespace = ['ai2', 'test1']
// const nsTest = ns.namespaces && ns.namespaces.filter(item => testNamespace.includes(item.name))
// for (const namespace of nsTest) {
for (const namespace of ns.namespaces) {
const svcs = await getServicesFormat(client, namespace.name)
for (const svc of svcs) {
if (svc.serviceName === 'mysql') {
const latestDB = await awaitRequest({
url: `${APP_CONFIG.qaapiHost}/proconfig/getLatestSvcDB?namespace=${namespace.name}&type=json`,
method: 'get',
})
summary[namespace.name] = latestDB.data
const data = {
dbname: 'all(no_mall)',
dbname: 'latest',
mysqlName: 'mysql',
namespace: namespace.name,
not_delete_business_data: true,
......@@ -36,15 +43,24 @@ const syncDB = async (cluster) => {
})
if (res.code === '0000') {
logger.info('开始同步ns:', namespace.name)
logger.info('开始同步ns:', namespace.name, latestDB.data)
} else {
logger.info('同步ns失败:', namespace.name, res.data)
}
await sleep(60 * 1000)
await sleep(6 * 1000)
break
}
}
}
let text = ''
for (const i in summary) {
if (Object.prototype.hasOwnProperty.call(summary, i)) {
if (summary[i].length) {
text = `${text}${i} 同步的 latest svc db : ${summary[i].join('')}\n\n`
}
}
}
dingTalk('daily latest db同步结果', text, APP_CONFIG.latestDingRobot)
logger.info('dailySyncDB end')
}
......
......@@ -8,17 +8,17 @@ const container = require('../services/tke.containerService').create()
const getClient = require('../resource/getClient')
const dingTalk = require('../utils/dingTalk')
const sleep = require('../utils/sleep')
const APP_CONFIG = require('../config')
const makeResouce = require('./../resource/makeResouce')
const address = 'https://oapi.dingtalk.com/robot/send?access_token=99e801a2cf26680e6ce09cb12f830c21a03ae3df07d18f6a38e1db54c0e95f2c'
const deploy = async (cluster) => {
logger.info('deployLatest start')
const client = await getClient(cluster)
const ns = await getAllNamespace(client.clientInfo)
const summary = {}
// // for test
// const testNamespace = ['ka3', 'xjfq']
// const testNamespace = ['ai2', 'xjfq']
// const nsTest = ns.namespaces && ns.namespaces.filter(item => testNamespace.includes(item.name))
// for (const namespace of nsTest) {
for (const namespace of ns.namespaces) {
......@@ -68,20 +68,24 @@ const deploy = async (cluster) => {
logger.info('ns:', namespace.name, '检查完毕')
}
let text = ''
for (const i in summary) {
if (Object.prototype.hasOwnProperty.call(summary, i)) {
text = `${text}${i}重新部署的latest : ${summary[i].latestArray.join('')}\n\n`
+ `${i}重新部署的master : ${summary[i].masterArray.join('')} \n\n`
+ ' \n\n'
if (summary[i].latestArray.length) {
text = `${text}${i} 重新部署的 latest : ${summary[i].latestArray.join('')}\n\n`
}
if (summary[i].masterArray.length) {
text = `${text}${i} 重新部署的 latest : ${summary[i].masterArray.join('')}\n\n`
}
}
}
dingTalk('daily latest 部署结果', text, address)
dingTalk('daily latest 部署结果', text, APP_CONFIG.latestDingRobot)
logger.info('deployLatest end')
}
module.exports = () => {
// schedule.scheduleJob('*/4 * * * *', async () => {
// schedule.scheduleJob('*/2 * * * *', async () => {
schedule.scheduleJob('0 3 * * *', async () => {
try {
await deploy('qa')
......
......@@ -14,4 +14,5 @@ module.exports = {
'acs-batch', 'acs-quartz', 'acs-service', 'pcm', 'vcc-talos', 'app-server', 'smart-recruitment-spyder', 'cash-loan-flow-report',
],
qaapiHost: 'http://qaapi.liangkebang.com',
latestDingRobot: 'https://oapi.dingtalk.com/robot/send?access_token=99e801a2cf26680e6ce09cb12f830c21a03ae3df07d18f6a38e1db54c0e95f2c',
}
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