diff --git a/src/core/Repository.ts b/src/core/Repository.ts index c369215..71e8b11 100644 --- a/src/core/Repository.ts +++ b/src/core/Repository.ts @@ -74,7 +74,9 @@ export default class Repository { const token = await getToken(this); if (originalToken != token) { this._model.source.accessToken = token; - await this._model.save(); + if (isConnected) { + await this._model.save(); + } } this.checkedToken = true; return token; @@ -461,9 +463,11 @@ export default class Repository { span.setAttribute("repoId", this.repoId); try { await storage.rm(this.repoId); - } finally { this.model.isReseted = true; - await this.model.save(); + if (isConnected) { + await this.model.save(); + } + } finally { span.end(); } } @@ -509,7 +513,9 @@ export default class Repository { const files = await this.files(); this._model.size = recursiveCount(files); - await this._model.save(); + if (isConnected) { + await this._model.save(); + } return this._model.size; } finally { span.end(); diff --git a/src/queue/processes/downloadRepository.ts b/src/queue/processes/downloadRepository.ts index 532c1d7..91322ca 100644 --- a/src/queue/processes/downloadRepository.ts +++ b/src/queue/processes/downloadRepository.ts @@ -30,7 +30,11 @@ export default async function (job: SandboxedJob) { ) { return clearInterval(statusInterval); } - if (repo.status && repo.model.statusMessage !== progress?.status) { + if ( + progress && + repo.status && + repo.model.statusMessage !== progress?.status + ) { console.log( `[QUEUE] Progress: ${job.data.repoId} ${progress.status}` ); @@ -45,12 +49,9 @@ export default async function (job: SandboxedJob) { progress = o; job.updateProgress(o); } - updateProgress({ status: "get_repo" }); try { - updateProgress({ status: "resetSate" }); await repo.resetSate(RepositoryStatus.PREPARING, ""); await repo.anonymize(updateProgress); - updateProgress({ status: RepositoryStatus.READY }); console.log(`[QUEUE] ${job.data.repoId} is downloaded`); } catch (error) { updateProgress({ status: "error" }); @@ -65,7 +66,7 @@ export default async function (job: SandboxedJob) { } } catch (error: any) { console.error(error); - job.updateProgress({ status: "error", error: error }); + clearInterval(statusInterval); await repo.updateStatus(RepositoryStatus.ERROR, error.message); span.recordException(error as Exception); console.log(`[QUEUE] ${job.data.repoId} is finished with an error`);