Commit ceb8c3b6 authored by 智勇's avatar 智勇

同步latest库

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