spider-task.js 651 Bytes
const schedule = require('node-schedule');
const path = require('path');
const Nedb = require('nedb-promise');
const dayjs = require('dayjs');

const spider = require('../libs/spider');

const db = new Nedb({
  filename: path.join(__dirname, 'db/data.json'),
  autoload: true
});

const ids = [20, 11172, 11538, 11653, 9536, 9431, 2358, 11621, 11408, 14546, 11746, 2355, 8815, 9670, 8708];

schedule.scheduleJob('0 */1 * * * *', async() => {
  const date = dayjs().format('YYYY-MM-DD HH:mm');

  console.log(`start scheduleJob, ${date}`);

  const result = await spider(ids);

  db.insert(result.map(r => {
    r.date = date;
    return r;
  }));
});