fix: only expire repositories that are ready

This commit is contained in:
tdurieux
2021-08-14 05:28:38 +02:00
parent cd9de704db
commit 37c324228c
2 changed files with 10 additions and 10 deletions
+9 -10
View File
@@ -152,11 +152,10 @@ export default class Repository {
(f) => f.name == branch.name (f) => f.name == branch.name
)[0].commit; )[0].commit;
this._model.anonymizeDate = new Date(); this._model.anonymizeDate = new Date();
await this.updateStatus("preparing");
console.log( console.log(
`${this._model.repoId} will be updated to ${this._model.source.commit}` `${this._model.repoId} will be updated to ${this._model.source.commit}`
); );
await this.resetSate(); await this.resetSate("preparing");
await this.anonymize(); await this.anonymize();
} }
} }
@@ -191,7 +190,6 @@ export default class Repository {
async updateStatus(status: RepositoryStatus, errorMessage?: string) { async updateStatus(status: RepositoryStatus, errorMessage?: string) {
this._model.status = status; this._model.status = status;
this._model.errorMessage = errorMessage; this._model.errorMessage = errorMessage;
this._model.status = status;
await this._model.save(); await this._model.save();
} }
@@ -199,26 +197,27 @@ export default class Repository {
* Expire the repository * Expire the repository
*/ */
async expire() { async expire() {
await this.updateStatus("expired"); this.resetSate("expired");
await this.resetSate();
} }
/** /**
* Remove the repository * Remove the repository
*/ */
async remove() { async remove() {
await this.updateStatus("removed"); this.resetSate("removed");
await this.resetSate();
} }
/** /**
* Reset/delete the state of the repository * Reset/delete the state of the repository
*/ */
private async resetSate() { private async resetSate(status?: RepositoryStatus) {
if (status) this._model.status = status;
this._model.size = 0; this._model.size = 0;
this._model.originalFiles = null; this._model.originalFiles = null;
await this._model.save(); return Promise.all([
await storage.rm(this._model.repoId + "/"); this._model.save(),
storage.rm(this._model.repoId + "/"),
]);
} }
/** /**
+1
View File
@@ -116,6 +116,7 @@ export default class User {
const promises = []; const promises = [];
for (let repo of repositories) { for (let repo of repositories) {
if ( if (
repo.status == "ready" &&
repo.options.expirationMode != "never" && repo.options.expirationMode != "never" &&
repo.options.expirationDate != null && repo.options.expirationDate != null &&
repo.options.expirationDate < new Date() repo.options.expirationDate < new Date()