Commit e01acff0 by 马玮

Op logs

parent c96c86c7
...@@ -23,11 +23,12 @@ class DI { ...@@ -23,11 +23,12 @@ class DI {
static getLogger() { static getLogger() {
const level = process.env.LOG_LEVEL || 'info'; const level = process.env.LOG_LEVEL || 'info';
const appenders = (process.env.LOG_TYPE ? process.env.LOG_TYPE.split(',') : null) || [ 'console', 'carspider' ]; const appenders = (process.env.LOG_TYPE ? process.env.LOG_TYPE.split(',') : null) || [ 'console', 'carspider' ];
// maxLogSize: 10485760 // 按文件大小回滚配置,待以后备用
// { type: 'file', filename: `${__basedir}/logs/dealer/carspider.log`, maxLogSize: 10485760, backups: 3, compress: false }
log4js.configure({ log4js.configure({
appenders: { appenders: {
console: { type: 'console' }, console: { type: 'console' },
carspider: { type: 'file', filename: `${__basedir}/logs/dealer/carspider.log`, maxLogSize: 1048576, backups: 3, compress: false }, carspider: { type: 'dateFile', filename: `${__basedir}/logs/dealer/carspider.log` },
}, },
categories: { categories: {
default: { appenders: appenders, level: level } default: { appenders: appenders, level: level }
......
...@@ -17,6 +17,14 @@ class Base { ...@@ -17,6 +17,14 @@ class Base {
this.maxLoginTimes = 3; this.maxLoginTimes = 3;
} }
async execute() {
try {
await this[this.params.task]();
} catch (e) {
logger.fatal(`accountID: ${this.params.accountID}, 系统异常: ${e}`);
}
}
async login() { async login() {
console.log('子类需要重载此方法'); console.log('子类需要重载此方法');
} }
......
...@@ -27,24 +27,6 @@ class Autohome extends Base { ...@@ -27,24 +27,6 @@ class Autohome extends Base {
this.params = params; this.params = params;
} }
async execute() {
try {
switch (this.params.task) {
case 'login': {
return await this.login();
}
case 'tryLogin': {
return await this.tryLogin();
}
case 'fetchClues': {
return await this.fetchClues();
}
}
} catch (e) {
logger.fatal(`accountID: ${this.params.accountID}, 系统异常: ${e}`);
}
}
async tryLogin() { async tryLogin() {
// 随机返回登录状态 // 随机返回登录状态
// return [new errors.TryLoginError('登录失效'), randomInt(0, 1)]; // return [new errors.TryLoginError('登录失效'), randomInt(0, 1)];
......
...@@ -27,23 +27,6 @@ class Easypass extends Base { ...@@ -27,23 +27,6 @@ class Easypass extends Base {
this.params = params; this.params = params;
} }
async execute() {
switch (this.params.task) {
case 'login': {
await this.login();
return;
}
case 'tryLogin': {
await this.tryLogin();
return;
}
case 'fetchClues': {
await this.fetchClues();
return;
}
}
}
async tryLogin() { async tryLogin() {
// 随机返回登录状态 // 随机返回登录状态
// return [new errors.TryLoginError('登录失效'), randomInt(0, 1)]; // return [new errors.TryLoginError('登录失效'), randomInt(0, 1)];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment