forked from wsmud/daily
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
39 lines (34 loc) · 1.11 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const fs = require('fs');
const yaml = require('js-yaml');
const { Command } = require('commander');
const schedule = require('node-schedule');
const Daily = require('./source/librarys/daily');
const program = new Command();
program
.option('-r, --run', '立即运行一次')
.option('-d, --debug', 'debug模式')
.option('-t --time <cron>', '设置定时<cron表达式>');
program.parse(process.argv);
const options = program.opts();
global.debugMode = options.debug ? true : false;
function loginQueue(configs, userConfig) {
const user = new Daily(userConfig);
user.on('CLOSE', () => {
if (configs.length > 0) {
const nextConfig = configs.shift();
loginQueue(configs, nextConfig);
}
});
}
if (options.run) {
const configs = yaml.load(fs.readFileSync('config.yaml'));
configs.splice(0, 30).forEach((userConfig) => {
loginQueue(configs, userConfig);
});
}
schedule.scheduleJob(options.time ? options.time : '5 5 5 * * *', () => {
const configs = yaml.load(fs.readFileSync('config.yaml'));
configs.splice(0, 30).forEach((userConfig) => {
loginQueue(configs, userConfig);
});
});