From 9221cffead647f263565107180dc51294d934aa4 Mon Sep 17 00:00:00 2001 From: pan <1029559041@qq.com> Date: Sat, 10 Oct 2020 15:39:26 +0800 Subject: [PATCH] init --- routes/index.js | 53 ++++++++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/routes/index.js b/routes/index.js index f1d6d57..13ec7bf 100644 --- a/routes/index.js +++ b/routes/index.js @@ -51,38 +51,45 @@ router.post('/deploy', function(req, res, next) { //仓库描述信息 const description=req.body.repository.description - startDeploy[name]={ - startTime:moment(updated_at), - description:description - } - dingding(`开始自动部署${c.repository.description}|${name},更新日志${commitsMsg}`) - - const promise = new Promise((resolve, reject) => { - const spawnObj = spawn('updateRisk', [name], {encoding: 'utf-8'}); - spawnObj.stdout.on('data', function(chunk) { - info(chunk.toString()); - }); - spawnObj.stderr.on('data', (data) => { - error(data); - }); - spawnObj.on('close', function(code) { - info('close code : ' + code); - }) - spawnObj.on('exit', (code) => { - info('exit code : ' + code); - resolve(true) + try { + startDeploy[name] = { + startTime: moment(updated_at), + description: description + } + + dingding(`开始自动部署${c.repository.description}|${name},更新日志${commitsMsg}`) + + const promise = new Promise((resolve, reject) => { + const spawnObj = spawn('updateRisk', [name], {encoding: 'utf-8'}); + spawnObj.stdout.on('data', function (chunk) { + info(chunk.toString()); + }); + spawnObj.stderr.on('data', (data) => { + error(data); + }); + spawnObj.on('close', function (code) { + info('close code : ' + code); + }) + spawnObj.on('exit', (code) => { + info('exit code : ' + code); + resolve(true) + }) }) - }) - res.json({message:`仓库代码${req.body.repository.ssh_url}部署中`}) + res.json({message: `仓库代码${req.body.repository.ssh_url}部署中`}) + } catch (e) { + error(e) + res.json({message: `仓库代码${req.body.repository.ssh_url}部署出现异常`}) + } + }); //部署完毕事件 router.get('/finsh', function(req, res, next) { dingding(`${req.query.name}|${startDeploy[req.query.name].description}自动部署成功, - 花费时间:${moment().diff(startDeploy[req.query.name].startTime,'seconds')}`) + 花费时间:${moment().diff(startDeploy[req.query.name].startTime,'seconds')}秒`) res.json({message:`仓库代码${req.query.name}部署成功`}) });