From 9ecfdae9d7c7f1efa73f11d952936171ee52c749 Mon Sep 17 00:00:00 2001 From: tdurieux Date: Thu, 6 Apr 2023 13:36:36 +0200 Subject: [PATCH] fix: protect against double save --- src/source/GitHubDownload.ts | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/source/GitHubDownload.ts b/src/source/GitHubDownload.ts index 5f634d9..a544652 100644 --- a/src/source/GitHubDownload.ts +++ b/src/source/GitHubDownload.ts @@ -10,6 +10,7 @@ import GitHubBase from "./GitHubBase"; import AnonymizedFile from "../AnonymizedFile"; import { RepositoryStatus, SourceBase } from "../types"; import AnonymousError from "../AnonymousError"; +import { tryCatch } from "bullmq"; export default class GitHubDownload extends GitHubBase implements SourceBase { constructor( @@ -91,13 +92,13 @@ export default class GitHubDownload extends GitHubBase implements SourceBase { const that = this; async function updateProgress() { - if (progress && that.repository.status == RepositoryStatus.DOWNLOAD) { - await that.repository.updateStatus( - that.repository.status, - progress.transferred.toString() - ); - } if (inDownload) { + if (progress && that.repository.status == RepositoryStatus.DOWNLOAD) { + await that.repository.updateStatus( + that.repository.status, + progress.transferred.toString() + ); + } progressTimeout = setTimeout(updateProgress, 1500); } } @@ -123,7 +124,11 @@ export default class GitHubDownload extends GitHubBase implements SourceBase { } this.repository.model.isReseted = false; - await this.repository.updateStatus(RepositoryStatus.READY); + try { + await this.repository.updateStatus(RepositoryStatus.READY); + } catch (error) { + console.error(error); + } } async getFileContent(file: AnonymizedFile): Promise {