Skip to content

Commit

Permalink
Only log events after they are completely successful.
Browse files Browse the repository at this point in the history
This awaits for all other tasks to be completed (including other uploads, and
even the unlocking) so downstream systems aren't hit with failed operations.
  • Loading branch information
LTLA committed Dec 11, 2023
1 parent 9a1a45a commit 32e51ee
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
5 changes: 2 additions & 3 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, env, nonblockers) {

let latpath = pkeys.latestVersion(project, asset);
let latest = await s3.quickFetchJson(latpath, env, { mustWork: false });
let is_latest = true;
var is_latest = true;
if (latest !== null) {
let latest_info = await s3.quickFetchJson(pkeys.versionSummary(project, asset, latest.version), env);
let my_finish = Date.parse(info.upload_finished);
Expand All @@ -45,12 +45,11 @@ export async function approveProbationHandler(request, env, nonblockers) {
await s3.quickUploadJson(latpath, { version: version }, env);
}

await change.addChangelog({ type: "add-version", project, asset, version, latest: is_latest }, env);

} finally {
await lock.unlockProject(project, env);
}

await change.addChangelog({ type: "add-version", project, asset, version, latest: is_latest }, env);
return new Response(null, { status: 200 });
}

Expand Down
11 changes: 4 additions & 7 deletions src/remove.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@ export async function removeProjectHandler(request, env, nonblockers) {
try {
// Add trailing slash to avoid deleting a project that starts with 'project'.
await s3.quickRecursiveDelete(project + "/", env);

await change.addChangelog({ type: "delete-project", project }, env);
} finally {
await lock.unlockProject(project, env);
}

await change.addChangelog({ type: "delete-project", project }, env);
return new Response(null, { status: 200 });
}

Expand All @@ -45,12 +44,11 @@ export async function removeProjectAssetHandler(request, env, nonblockers) {
// Add trailing slash to avoid deleting an asset that starts with 'asset'.
let freed = await s3.quickRecursiveDelete(project + "/" + asset + "/", env);
await quot.updateQuotaOnDeletion(project, freed, env);

await change.addChangelog({ type: "delete-asset", project, asset }, env);
} finally {
await lock.unlockProject(project, env);
}

await change.addChangelog({ type: "delete-asset", project, asset }, env);
return new Response(null, { status: 200 });
}

Expand All @@ -75,16 +73,15 @@ export async function removeProjectAssetVersionHandler(request, env, nonblockers
// Need to go through and update the latest version of the asset, in case
// we just deleted the latest version.
let linfo = await s3.quickFetchJson(pkeys.latestVersion(project, asset), env, { mustWork: false });
let was_latest = (linfo !== null && linfo.version == version);
var was_latest = (linfo !== null && linfo.version == version);
if (was_latest) {
await vers.updateLatestVersion(project, asset, env);
}

await change.addChangelog({ type: "delete-version", project, asset, version, latest: was_latest }, env);

} finally {
await lock.unlockProject(project, env);
}

await change.addChangelog({ type: "delete-version", project, asset, version, latest: was_latest }, env);
return new Response(null, { status: 200 });
}
8 changes: 5 additions & 3 deletions src/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -403,10 +403,10 @@ export async function completeUploadHandler(request, env, nonblockers) {
preparation.push(s3.quickUploadJson(project + "/" + asset + "/" + version + "/" + k + "..links", v, env));
}

if (!info.on_probation) {
var is_official = (!info.on_probation);
if (is_official) {
preparation.push(s3.quickUploadJson(pkeys.latestVersion(project, asset), { "version": version }, env));
delete info.on_probation;
preparation.push(change.addChangelog({ type: "add-version", project, asset, version, latest: true }, env));
}

info.upload_finish = (new Date).toISOString();
Expand All @@ -423,8 +423,10 @@ export async function completeUploadHandler(request, env, nonblockers) {
await Promise.all(preparation);
}

// Release lock once we're clear.
await lock.unlockProject(project, env);
if (is_official) {
preparation.push(change.addChangelog({ type: "add-version", project, asset, version, latest: true }, env));
}
return new Response(null, { status: 200 });
}

Expand Down

0 comments on commit 32e51ee

Please sign in to comment.