From dc1ff2d0b85cc11b150bde8f02a67d85ac435761 Mon Sep 17 00:00:00 2001 From: tdurieux Date: Sun, 26 Sep 2021 08:01:52 +0200 Subject: [PATCH] feat: retry 3 times to download a repository --- src/Repository.ts | 2 +- src/routes/repository-private.ts | 5 ++++- src/routes/repository-public.ts | 6 +++--- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Repository.ts b/src/Repository.ts index b2ba44a..fd12437 100644 --- a/src/Repository.ts +++ b/src/Repository.ts @@ -185,7 +185,7 @@ export default class Repository { this._model.anonymizeDate = new Date(); console.log(`${this._model.repoId} will be updated to ${newCommit}`); await this.resetSate("preparing"); - await downloadQueue.add(this, { jobId: this.repoId }); + await downloadQueue.add(this, { jobId: this.repoId, attempts: 3 }); } } } diff --git a/src/routes/repository-private.ts b/src/routes/repository-private.ts index 2048649..9082cef 100644 --- a/src/routes/repository-private.ts +++ b/src/routes/repository-private.ts @@ -432,7 +432,10 @@ router.post("/", async (req: express.Request, res: express.Response) => { } res.send({ status: repo.status }); - downloadQueue.add(new Repository(repo), { jobId: repo.repoId }); + downloadQueue.add(new Repository(repo), { + jobId: repo.repoId, + attempts: 3, + }); } catch (error) { if (error.message?.indexOf(" duplicate key") > -1) { return handleError( diff --git a/src/routes/repository-public.ts b/src/routes/repository-public.ts index ff1e3fa..21b652f 100644 --- a/src/routes/repository-public.ts +++ b/src/routes/repository-public.ts @@ -87,11 +87,11 @@ router.get( fiveMinuteAgo.setMinutes(fiveMinuteAgo.getMinutes() - 5); if (repo.status != "ready") { if ( - repo.model.statusDate < fiveMinuteAgo + repo.model.statusDate < fiveMinuteAgo // && repo.status != "preparing" ) { await repo.updateStatus("preparing"); - await downloadQueue.add(repo, { jobId: repo.repoId }); + await downloadQueue.add(repo, { jobId: repo.repoId, attempts: 3 }); } if (repo.status == "error") { throw new AnonymousError( @@ -121,7 +121,7 @@ router.get( !!config.ENABLE_DOWNLOAD && repo.source.type == "GitHubDownload"; } - + res.header("Cache-Control", "no-cache"); res.json({ url: redirectURL,