Skip to content

Commit

Permalink
Added an unlocking function.
Browse files Browse the repository at this point in the history
  • Loading branch information
LTLA committed Dec 1, 2023
1 parent 15b154f commit 9df9a2b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/lock.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ export async function lockProject(project, asset, version, user_name) {
return;
}

export async function unlockProject(project, asset, version) {
let bound_bucket = s3.getR2Binding();
let lck = pkeys.lock(project, asset);
await bound_bucket.delete(lck);
}

export async function checkLock(project, asset, version, user_name) {
let bound_bucket = s3.getR2Binding();
let lck = pkeys.lock(project, asset);
Expand Down
4 changes: 2 additions & 2 deletions src/probation.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export async function approveProbationHandler(request, nonblockers) {
throw new utils.HttpError("failed to update version summary", 500);
}
} finally {
await bound_bucket.delete(pkeys.lock(project, asset));
await lck.unlockProject(project, asset);
}

return new Response(null, { status: 200 });
Expand Down Expand Up @@ -70,7 +70,7 @@ export async function rejectProbationHandler(request, nonblockers) {

await utils.quickRecursiveDelete(project + "/" + asset + "/" + version + "/");
} finally {
await bound_bucket.delete(pkeys.lock(project, asset));
await lck.unlockProject(project, asset);
}

return new Response(null, { status: 200 });
Expand Down
3 changes: 3 additions & 0 deletions tests/lock.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ test("project locking works as expected", async () => {

expect(await lock.isLocked("test-lock-test", "locker")).toBe(true);
expect(await lock.isLocked("test-lock-test", "other")).toBe(false);

await lock.unlockProject("test-lock-test", "locker");
expect(await lock.isLocked("test-lock-test", "locker")).toBe(false);
})

0 comments on commit 9df9a2b

Please sign in to comment.