mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-11-14 00:07:00 +01:00
fix: preserve publication fences during download progress
This commit is contained in:
1 parent
d0b217a448
commit
807e38dfc7
7 files changed
+112
-4
No files matched your search
+30
-1
@@ -524,7 +524,7 @@ export default class Repository {
|
||||
this.status == RepositoryStatus.PREPARING ||
|
||||
this.status == RepositoryStatus.QUEUE ||
|
||||
(this.status == RepositoryStatus.DOWNLOAD &&
|
||||
this._model.statusDate > fiveMinuteAgo)
|
||||
this.statusActivityDate > fiveMinuteAgo)
|
||||
) {
|
||||
const rlMatch = (this._model.statusMessage || "").match(/^rate_limited:(\d+)$/);
|
||||
if (rlMatch) {
|
||||
@@ -840,6 +840,35 @@ export default class Repository {
|
||||
*/
|
||||
public protectLifecycle = false;
|
||||
|
||||
get statusActivityDate(): Date {
|
||||
const { statusDate, progressDate } = this.model;
|
||||
return this.status === RepositoryStatus.DOWNLOAD && progressDate &&
|
||||
(!statusDate || progressDate > statusDate) ? progressDate : statusDate;
|
||||
}
|
||||
|
||||
/** Progress is activity, not a lifecycle transition or a new publication fence. */
|
||||
async updateProgressMessage(statusMessage: string) {
|
||||
const status = this.status;
|
||||
if (status !== RepositoryStatus.DOWNLOAD) return;
|
||||
const statusDate = this.model.statusDate;
|
||||
const progressDate = new Date();
|
||||
if (isConnected) {
|
||||
const result = await AnonymizedRepositoryModel.updateOne({
|
||||
_id: this.model._id, ...this.refreshFilter(), status,
|
||||
statusDate: statusDate || { $exists: false },
|
||||
anonymizeDate: this.model.anonymizeDate,
|
||||
"source.commit": this.model.source.commit || { $exists: false },
|
||||
"githubAccess.revision": this.model.githubAccess?.revision || { $exists: false },
|
||||
}, { $set: { statusMessage, progressDate } }).exec();
|
||||
if (!result.matchedCount) return;
|
||||
}
|
||||
// An awaited write can finish after this instance has moved to READY.
|
||||
if (this.status === status && this.model.statusDate?.getTime() === statusDate?.getTime()) {
|
||||
this.model.statusMessage = statusMessage;
|
||||
this.model.progressDate = progressDate;
|
||||
}
|
||||
}
|
||||
|
||||
async updateStatus(status: RepositoryStatus, statusMessage?: string) {
|
||||
if (status !== RepositoryStatus.ARCHIVED) this.assertNotArchived();
|
||||
if (!status) return this.model;
|
||||
|
||||
@@ -17,6 +17,7 @@ const AnonymizedRepositorySchema = new Schema({
|
||||
default: "preparing",
|
||||
},
|
||||
statusDate: Date,
|
||||
progressDate: Date,
|
||||
refreshToken: { type: String, select: false },
|
||||
refreshUntil: { type: Date, select: false },
|
||||
archivedAt: Date,
|
||||
|
||||
@@ -7,6 +7,7 @@ export interface IAnonymizedRepository {
|
||||
status?: RepositoryStatus;
|
||||
statusMessage?: string;
|
||||
statusDate: Date;
|
||||
progressDate?: Date;
|
||||
archivedAt?: Date;
|
||||
archiveReason?: string;
|
||||
archiveCachePending?: boolean;
|
||||
|
||||
@@ -75,7 +75,7 @@ export default async function (job: SandboxedJob<RepoJobData, void>) {
|
||||
repoId: job.data.repoId,
|
||||
status: progress.status,
|
||||
});
|
||||
await repo.updateStatus(repo.status, progress?.status || "");
|
||||
await repo.updateProgressMessage(progress?.status || "");
|
||||
}
|
||||
} catch {
|
||||
// ignore error
|
||||
|
||||
@@ -159,7 +159,7 @@ router.post(
|
||||
repo.status == RepositoryStatus.PREPARING ||
|
||||
repo.status == RepositoryStatus.QUEUE ||
|
||||
(repo.status == RepositoryStatus.DOWNLOAD &&
|
||||
repo.model.statusDate > new Date(Date.now() - 5 * 60_000)) ||
|
||||
repo.statusActivityDate > new Date(Date.now() - 5 * 60_000)) ||
|
||||
repo.status == RepositoryStatus.REMOVING ||
|
||||
repo.status == RepositoryStatus.EXPIRING
|
||||
) {
|
||||
|
||||
@@ -323,7 +323,7 @@ router.get(
|
||||
if (repo.status != "ready") {
|
||||
if (
|
||||
repo.status != RepositoryStatus.QUEUE &&
|
||||
repo.model.statusDate < fiveMinuteAgo
|
||||
repo.statusActivityDate < fiveMinuteAgo
|
||||
) {
|
||||
await repo.updateStatus(RepositoryStatus.PREPARING);
|
||||
await downloadQueue.add(repo.repoId, { repoId: repo.repoId }, {
|
||||
|
||||
Reference in new issue
Block a user