40 lines
908 B
JavaScript
40 lines
908 B
JavaScript
import mongoose from 'mongoose'
|
||
import schedule from 'node-schedule'
|
||
|
||
import config from '../config/config'
|
||
import getCate from './spider/cate'
|
||
|
||
import logger from '../src/utils/logger'
|
||
|
||
const db = mongoose.connection
|
||
|
||
db.on('error', function(err) {
|
||
logger.error(err)
|
||
process.exit(1)
|
||
})
|
||
db.once('open', function() {
|
||
console.log('Connected to db.')
|
||
})
|
||
mongoose.connect(config.db_taptap, {
|
||
useNewUrlParser: true,
|
||
useUnifiedTopology: true,
|
||
})
|
||
|
||
const scheduleCronstyle = () => {
|
||
console.log('TapTap已启动!')
|
||
const timer = schedule.scheduleJob('0 0 9 * * *', () => {
|
||
logger.info({}, new Date() + '开始收集数据!')
|
||
getAllData()
|
||
})
|
||
}
|
||
|
||
scheduleCronstyle()
|
||
|
||
function getAllData() {
|
||
setTimeout(getCate, 0, 'download')
|
||
setTimeout(getCate, 1200000, 'new')
|
||
setTimeout(getCate, 2400000, 'reserve')
|
||
setTimeout(getCate, 3600000, 'sell')
|
||
setTimeout(getCate, 4800000, 'played')
|
||
}
|