|
|
|
@ -22,6 +22,8 @@ export class Exporter {
|
|
|
|
|
private createdTimestamp: number; |
|
|
|
|
private username: string; |
|
|
|
|
private datasourceRef: DataSourceRef; |
|
|
|
|
private from: number; |
|
|
|
|
private to: number; |
|
|
|
|
|
|
|
|
|
private initCsvStream() { |
|
|
|
|
const csvStream = csv.createWriteStream({ headers: true }) |
|
|
|
@ -38,16 +40,19 @@ export class Exporter {
|
|
|
|
|
return csvStream; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public async updateStatus(status: string, progress: number) { |
|
|
|
|
public async updateStatus(status: string, progress: number, error?: string) { |
|
|
|
|
try { |
|
|
|
|
let time = moment().valueOf(); |
|
|
|
|
let data = { |
|
|
|
|
time, |
|
|
|
|
progress, |
|
|
|
|
status, |
|
|
|
|
error, |
|
|
|
|
username: this.username, |
|
|
|
|
exportedRows: this.exportedRows, |
|
|
|
|
progress: progress, |
|
|
|
|
status, |
|
|
|
|
datasourceRef: this.datasourceRef, |
|
|
|
|
from: this.from, |
|
|
|
|
to: this.to, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
await promisify(fs.writeFile, this.getFilePath('json'), JSON.stringify(data), 'utf8') |
|
|
|
@ -60,6 +65,8 @@ export class Exporter {
|
|
|
|
|
// TODO: rename `data` to `targets` or `queries`
|
|
|
|
|
public async export(data: Target[], datasourceUrl: string, username: string, from: number, to: number) { |
|
|
|
|
this.username = username; |
|
|
|
|
this.from = from; |
|
|
|
|
this.to = to; |
|
|
|
|
|
|
|
|
|
this.validateTargets(datasourceUrl, data); |
|
|
|
|
|
|
|
|
@ -103,10 +110,15 @@ export class Exporter {
|
|
|
|
|
const host = new URL(datasourceUrl).origin; |
|
|
|
|
const apiKey = apiKeys[host]; |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
const datasourceMetrics = await queryByConfig(target.metric, datasourceUrl, from, to, apiKey); |
|
|
|
|
|
|
|
|
|
columns = datasourceMetrics.columns; |
|
|
|
|
values = datasourceMetrics.values; |
|
|
|
|
} catch (e) { |
|
|
|
|
await this.updateStatus(ExportStatus.ERROR, (day + 1) / days, e.message); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(columns.length > 0) { |
|
|
|
|