forked from FoundKeyGang/FoundKey
More logs
This commit is contained in:
parent
08eb3851da
commit
0b2571858f
1 changed files with 9 additions and 0 deletions
|
@ -8,6 +8,9 @@ import autobind from 'autobind-decorator';
|
||||||
import * as mongo from 'mongodb';
|
import * as mongo from 'mongodb';
|
||||||
import db from '../db/mongodb';
|
import db from '../db/mongodb';
|
||||||
import { ICollection } from 'monk';
|
import { ICollection } from 'monk';
|
||||||
|
import Logger from '../misc/logger';
|
||||||
|
|
||||||
|
const logger = new Logger('chart');
|
||||||
|
|
||||||
const utc = moment.utc;
|
const utc = moment.utc;
|
||||||
|
|
||||||
|
@ -58,14 +61,18 @@ type Log<T extends Obj> = {
|
||||||
export default abstract class Chart<T> {
|
export default abstract class Chart<T> {
|
||||||
protected collection: ICollection<Log<T>>;
|
protected collection: ICollection<Log<T>>;
|
||||||
protected abstract async getTemplate(init: boolean, latest?: T, group?: any): Promise<T>;
|
protected abstract async getTemplate(init: boolean, latest?: T, group?: any): Promise<T>;
|
||||||
|
private name: string;
|
||||||
|
|
||||||
constructor(name: string, grouped = false) {
|
constructor(name: string, grouped = false) {
|
||||||
|
this.name = name;
|
||||||
this.collection = db.get<Log<T>>(`chart.${name}`);
|
this.collection = db.get<Log<T>>(`chart.${name}`);
|
||||||
|
|
||||||
const keys = {
|
const keys = {
|
||||||
span: -1,
|
span: -1,
|
||||||
date: -1
|
date: -1
|
||||||
} as { [key: string]: 1 | -1; };
|
} as { [key: string]: 1 | -1; };
|
||||||
if (grouped) keys.group = -1;
|
if (grouped) keys.group = -1;
|
||||||
|
|
||||||
this.collection.createIndex(keys, { unique: true });
|
this.collection.createIndex(keys, { unique: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,6 +162,8 @@ export default abstract class Chart<T> {
|
||||||
|
|
||||||
// 初期ログデータを作成
|
// 初期ログデータを作成
|
||||||
data = await this.getTemplate(true, null, group);
|
data = await this.getTemplate(true, null, group);
|
||||||
|
|
||||||
|
logger.info(`${this.name}: Initial commit created`);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in a new issue