From a7462884ba9f1d072d1a1bac97e5d4c25d338adf Mon Sep 17 00:00:00 2001 From: Alexander Lee Date: Thu, 22 Feb 2024 21:31:59 +0800 Subject: [PATCH 1/2] Revert "Chore/lock repos when repairing (#1149)" This reverts commit e911e2ef678277b3cff7333ae6cd89618c6f8b1e. --- src/routes/formsg/formsgGGsRepair.ts | 21 ++------------------- src/utils/mutex-utils.js | 8 ++++---- 2 files changed, 6 insertions(+), 23 deletions(-) diff --git a/src/routes/formsg/formsgGGsRepair.ts b/src/routes/formsg/formsgGGsRepair.ts index f8a6fce4b..2bf41a5e9 100644 --- a/src/routes/formsg/formsgGGsRepair.ts +++ b/src/routes/formsg/formsgGGsRepair.ts @@ -10,15 +10,12 @@ import { ResultAsync, errAsync, fromPromise, okAsync } from "neverthrow" import { config } from "@config/config" -import { lock, unlock } from "@utils/mutex-utils" - import { EFS_VOL_PATH_STAGING, EFS_VOL_PATH_STAGING_LITE, } from "@root/constants" import GitFileSystemError from "@root/errors/GitFileSystemError" import InitializationError from "@root/errors/InitializationError" -import LockedError from "@root/errors/LockedError" import { consoleLogger } from "@root/logger/console.logger" import logger from "@root/logger/logger" import { attachFormSGHandler } from "@root/middleware" @@ -117,20 +114,15 @@ export class FormsgGGsRepairRouter { } handleGGsFormSubmission = (repoNames: string[], requesterEmail: string) => { - const repairs: ResultAsync[] = [] + const repairs: ResultAsync[] = [] const clonedStagingRepos: string[] = [] const syncedStagingAndStagingLiteRepos: string[] = [] - const LOCK_TIME_SECONDS = 15 * 60 // 15 minutes repoNames.forEach((repoName) => { const repoUrl = `git@github.com:isomerpages/${repoName}.git` repairs.push( - ResultAsync.fromPromise( - lock(repoName, LOCK_TIME_SECONDS), - (err) => new LockedError(`Unable to lock repo ${repoName}`) - ) - .andThen(() => this.doesRepoNeedClone(repoName)) + this.doesRepoNeedClone(repoName) .andThen(() => { const isStaging = true return ( @@ -174,15 +166,6 @@ export class FormsgGGsRepairRouter { return okAsync(result) }) ) - .andThen((result) => { - // Failure to unlock is not blocking - ResultAsync.fromPromise(unlock(repoName), () => { - logger.error( - "Failed to unlock repo - repo will unlock after at most 15 min" - ) - }) - return okAsync(result) - }) ) }) diff --git a/src/utils/mutex-utils.js b/src/utils/mutex-utils.js index b0f19805b..fa623c383 100644 --- a/src/utils/mutex-utils.js +++ b/src/utils/mutex-utils.js @@ -35,10 +35,10 @@ const mockUnlock = (siteName) => { mockMutexObj[siteName] = false } -const lock = async (siteName, lockLengthSeconds = 60) => { +const lock = async (siteName) => { try { - const expiryTime = - Math.floor(new Date().valueOf() / 1000) + lockLengthSeconds + const ONE_MIN_FROM_CURR_DATE_IN_SECONDS_FROM_EPOCH_TIME = + Math.floor(new Date().valueOf() / 1000) + 60 if (isE2eTestRepo(siteName)) return if (!IS_DEV) { @@ -46,7 +46,7 @@ const lock = async (siteName, lockLengthSeconds = 60) => { TableName: MUTEX_TABLE_NAME, Item: { repo_id: siteName, - expdate: expiryTime, + expdate: ONE_MIN_FROM_CURR_DATE_IN_SECONDS_FROM_EPOCH_TIME, }, ConditionExpression: "attribute_not_exists(repo_id)", } From 6388fbcf62e0645adfc5bb4cbef37a4fed122664 Mon Sep 17 00:00:00 2001 From: Alexander Lee Date: Thu, 22 Feb 2024 21:33:03 +0800 Subject: [PATCH 2/2] 0.67.1 --- CHANGELOG.md | 6 ++++++ package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2fdebb0b4..e9c6f6b2b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,8 +4,14 @@ All notable changes to this project will be documented in this file. Dates are d Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). +#### [v0.67.1](https://github.com/isomerpages/isomercms-backend/compare/v0.67.0...v0.67.1) + +- Revert "Chore/lock repos when repairing (#1149)" [`a746288`](https://github.com/isomerpages/isomercms-backend/commit/a7462884ba9f1d072d1a1bac97e5d4c25d338adf) + #### [v0.67.0](https://github.com/isomerpages/isomercms-backend/compare/v0.66.4...v0.67.0) +> 22 February 2024 + - fix(start-commands): update commands to be different by env [`#1159`](https://github.com/isomerpages/isomercms-backend/pull/1159) - fix(dompurify): further limit src [`#1156`](https://github.com/isomerpages/isomercms-backend/pull/1156) - fix(file-ext): prevent users from bypassing checks on file extensions [`#1157`](https://github.com/isomerpages/isomercms-backend/pull/1157) diff --git a/package-lock.json b/package-lock.json index 91c0bd143..3956d1730 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "isomercms", - "version": "0.67.0", + "version": "0.67.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "isomercms", - "version": "0.67.0", + "version": "0.67.1", "dependencies": { "@aws-sdk/client-amplify": "^3.370.0", "@aws-sdk/client-cloudwatch-logs": "^3.370.0", diff --git a/package.json b/package.json index d2410929c..202c3f047 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "isomercms", - "version": "0.67.0", + "version": "0.67.1", "private": true, "scripts": { "build": "tsc -p tsconfig.build.json",