mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-02-13 10:52:53 +00:00
fix: fix webview & improve download progress
This commit is contained in:
@@ -17,18 +17,43 @@ export default async function (job: SandboxedJob<Repository, void>) {
|
||||
const span = trace.getTracer("ano-file").startSpan("proc.downloadRepository");
|
||||
span.setAttribute("repoId", job.data.repoId);
|
||||
console.log(`[QUEUE] ${job.data.repoId} is going to be downloaded`);
|
||||
let statusInterval: any = null;
|
||||
await connect();
|
||||
const repo = await getRepository(job.data.repoId);
|
||||
try {
|
||||
await connect();
|
||||
const repo = await getRepository(job.data.repoId);
|
||||
job.updateProgress({ status: "get_repo" });
|
||||
let progress: any = null;
|
||||
statusInterval = setInterval(async () => {
|
||||
try {
|
||||
if (
|
||||
repo.status == RepositoryStatus.READY ||
|
||||
repo.status == RepositoryStatus.ERROR
|
||||
) {
|
||||
return clearInterval(statusInterval);
|
||||
}
|
||||
if (repo.status && repo.model.statusMessage !== progress?.status) {
|
||||
console.log(
|
||||
`[QUEUE] Progress: ${job.data.repoId} ${progress.status}`
|
||||
);
|
||||
await repo.updateStatus(repo.status, progress?.status || "");
|
||||
}
|
||||
} catch (_) {
|
||||
// ignore error
|
||||
}
|
||||
}, 500);
|
||||
function updateProgress(obj: { status: string } | string) {
|
||||
const o = typeof obj === "string" ? { status: obj } : obj;
|
||||
progress = o;
|
||||
job.updateProgress(o);
|
||||
}
|
||||
updateProgress({ status: "get_repo" });
|
||||
try {
|
||||
job.updateProgress({ status: "resetSate" });
|
||||
updateProgress({ status: "resetSate" });
|
||||
await repo.resetSate(RepositoryStatus.PREPARING, "");
|
||||
job.updateProgress({ status: "download" });
|
||||
await repo.anonymize();
|
||||
await repo.anonymize(updateProgress);
|
||||
updateProgress({ status: RepositoryStatus.READY });
|
||||
console.log(`[QUEUE] ${job.data.repoId} is downloaded`);
|
||||
} catch (error) {
|
||||
job.updateProgress({ status: "error" });
|
||||
updateProgress({ status: "error" });
|
||||
if (error instanceof Error) {
|
||||
span.recordException(error as Exception);
|
||||
await repo.updateStatus(RepositoryStatus.ERROR, error.message);
|
||||
@@ -38,11 +63,14 @@ export default async function (job: SandboxedJob<Repository, void>) {
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
} catch (error: any) {
|
||||
console.error(error);
|
||||
job.updateProgress({ status: "error", error: error });
|
||||
await repo.updateStatus(RepositoryStatus.ERROR, error.message);
|
||||
span.recordException(error as Exception);
|
||||
console.log(`[QUEUE] ${job.data.repoId} is finished with an error`);
|
||||
} finally {
|
||||
clearInterval(statusInterval);
|
||||
span.end();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user