1 Star 1 Fork 54

轩少/job-timer

forked from lianzt/job-timer 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
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;
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
NodeJS
1
https://gitee.com/wangzhixuan/job-timer.git
git@gitee.com:wangzhixuan/job-timer.git
wangzhixuan
job-timer
job-timer
master

搜索帮助