From 5c88c5adbeed79f019fcc8aeb3231671acee9716 Mon Sep 17 00:00:00 2001 From: rozetko Date: Wed, 18 Jan 2023 18:27:42 +0300 Subject: [PATCH] add all errors to the progress --- src/services/exporter.ts | 66 ++++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/src/services/exporter.ts b/src/services/exporter.ts index 7930739..5711ad3 100644 --- a/src/services/exporter.ts +++ b/src/services/exporter.ts @@ -28,39 +28,39 @@ export class Exporter { private _task: ExportTask; public async export(task: ExportTask, datasourceUrl: string) { - this._task = _.cloneDeep(task); - this._task.id = uuidv4(); - this._task.progress = _.cloneDeep(DEFAULT_PROGRESS); - - const targets = task.queries.map((query: DashboardQuery) => new Target( - query.panel, - query.datasource, - )); - - this._validateTargets(datasourceUrl, targets); - - await this._updateProgress(); - - const queryConfigs = targets.map( - target => - new QueryConfig( - QueryType.GRAFANA, - { - ...target.datasource, - url: datasourceUrl - }, - target.panel.targets - ) - ); - - let from = +this._task.timeRange.from; - let to = +this._task.timeRange.to; - const days = Math.ceil((to - from) / MS_IN_DAY); - - console.log(`Total days: ${days}`); - - const stream = this._initCsvStream(); try { + this._task = _.cloneDeep(task); + this._task.id = uuidv4(); + this._task.progress = _.cloneDeep(DEFAULT_PROGRESS); + + const targets = task.queries.map((query: DashboardQuery) => new Target( + query.panel, + query.datasource, + )); + + this._validateTargets(datasourceUrl, targets); + + await this._updateProgress(); + + const queryConfigs = targets.map( + target => + new QueryConfig( + QueryType.GRAFANA, + { + ...target.datasource, + url: datasourceUrl + }, + target.panel.targets + ) + ); + + let from = +this._task.timeRange.from; + let to = +this._task.timeRange.to; + const days = Math.ceil((to - from) / MS_IN_DAY); + + console.log(`Total days: ${days}`); + + const stream = this._initCsvStream(); for(let day = 0; day < days; day++) { to = from + MS_IN_DAY; @@ -86,10 +86,10 @@ export class Exporter { from += MS_IN_DAY; } + stream.end(); } catch (e) { await this._updateProgress({ status: ExportStatus.ERROR, errorMessage: e.message }); } - stream.end(); } private _initCsvStream() {