mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-07-06 21:57:57 +02:00
fix: attempt at avoiding double save
This commit is contained in:
+10
-4
@@ -74,7 +74,9 @@ export default class Repository {
|
|||||||
const token = await getToken(this);
|
const token = await getToken(this);
|
||||||
if (originalToken != token) {
|
if (originalToken != token) {
|
||||||
this._model.source.accessToken = token;
|
this._model.source.accessToken = token;
|
||||||
await this._model.save();
|
if (isConnected) {
|
||||||
|
await this._model.save();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
this.checkedToken = true;
|
this.checkedToken = true;
|
||||||
return token;
|
return token;
|
||||||
@@ -461,9 +463,11 @@ export default class Repository {
|
|||||||
span.setAttribute("repoId", this.repoId);
|
span.setAttribute("repoId", this.repoId);
|
||||||
try {
|
try {
|
||||||
await storage.rm(this.repoId);
|
await storage.rm(this.repoId);
|
||||||
} finally {
|
|
||||||
this.model.isReseted = true;
|
this.model.isReseted = true;
|
||||||
await this.model.save();
|
if (isConnected) {
|
||||||
|
await this.model.save();
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
span.end();
|
span.end();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -509,7 +513,9 @@ export default class Repository {
|
|||||||
|
|
||||||
const files = await this.files();
|
const files = await this.files();
|
||||||
this._model.size = recursiveCount(files);
|
this._model.size = recursiveCount(files);
|
||||||
await this._model.save();
|
if (isConnected) {
|
||||||
|
await this._model.save();
|
||||||
|
}
|
||||||
return this._model.size;
|
return this._model.size;
|
||||||
} finally {
|
} finally {
|
||||||
span.end();
|
span.end();
|
||||||
|
|||||||
@@ -30,7 +30,11 @@ export default async function (job: SandboxedJob<Repository, void>) {
|
|||||||
) {
|
) {
|
||||||
return clearInterval(statusInterval);
|
return clearInterval(statusInterval);
|
||||||
}
|
}
|
||||||
if (repo.status && repo.model.statusMessage !== progress?.status) {
|
if (
|
||||||
|
progress &&
|
||||||
|
repo.status &&
|
||||||
|
repo.model.statusMessage !== progress?.status
|
||||||
|
) {
|
||||||
console.log(
|
console.log(
|
||||||
`[QUEUE] Progress: ${job.data.repoId} ${progress.status}`
|
`[QUEUE] Progress: ${job.data.repoId} ${progress.status}`
|
||||||
);
|
);
|
||||||
@@ -45,12 +49,9 @@ export default async function (job: SandboxedJob<Repository, void>) {
|
|||||||
progress = o;
|
progress = o;
|
||||||
job.updateProgress(o);
|
job.updateProgress(o);
|
||||||
}
|
}
|
||||||
updateProgress({ status: "get_repo" });
|
|
||||||
try {
|
try {
|
||||||
updateProgress({ status: "resetSate" });
|
|
||||||
await repo.resetSate(RepositoryStatus.PREPARING, "");
|
await repo.resetSate(RepositoryStatus.PREPARING, "");
|
||||||
await repo.anonymize(updateProgress);
|
await repo.anonymize(updateProgress);
|
||||||
updateProgress({ status: RepositoryStatus.READY });
|
|
||||||
console.log(`[QUEUE] ${job.data.repoId} is downloaded`);
|
console.log(`[QUEUE] ${job.data.repoId} is downloaded`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
updateProgress({ status: "error" });
|
updateProgress({ status: "error" });
|
||||||
@@ -65,7 +66,7 @@ export default async function (job: SandboxedJob<Repository, void>) {
|
|||||||
}
|
}
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
job.updateProgress({ status: "error", error: error });
|
clearInterval(statusInterval);
|
||||||
await repo.updateStatus(RepositoryStatus.ERROR, error.message);
|
await repo.updateStatus(RepositoryStatus.ERROR, error.message);
|
||||||
span.recordException(error as Exception);
|
span.recordException(error as Exception);
|
||||||
console.log(`[QUEUE] ${job.data.repoId} is finished with an error`);
|
console.log(`[QUEUE] ${job.data.repoId} is finished with an error`);
|
||||||
|
|||||||
Reference in New Issue
Block a user