37 Star 125 Fork 55

lianzt / job-timer

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
db_helper.js 822 Bytes
一键复制 编辑 原始数据 按行查看 历史
jufan 提交于 2018-08-13 18:20 . 增加对 spark streaming 任务支持
const MongoClient = require('mongodb').MongoClient
const util = require('./util')
const config = require('./config')
const logger = util.getLogger('db_helper')
let conn
module.exports = {
async connect () {
if (module.exports.idConnected)
return
try{
conn = await MongoClient.connect(config.mongo.url)
module.exports.idConnected = true //数据连接状态
let db = conn.db()
module.exports.db = db
module.exports.jobs = db.collection('jobs')
module.exports.logs = db.collection('logs')
module.exports.test = db.collection('test')
logger.info('连接 mongodb 成功')
}catch(e){
logger.error('连接 mongodb 异常:', e)
module.exports.idConnected = false //数据连接状态
conn && conn.close()
throw e;
}
}
}
NodeJS
1
https://gitee.com/lianzt/job-timer.git
git@gitee.com:lianzt/job-timer.git
lianzt
job-timer
job-timer
master

搜索帮助