Let a later cleanup group take over a source whose earlier group has finished
When the same file was registered for cleanup a second time (for example a repeated upload to one hoster), both groups blocked each other through the source lease and the file was never deleted, even after every hoster had succeeded. A later group now takes over the lease once every job of the earlier group has reached a terminal state; the earlier group is audited as superseded. Groups with a still running job keep blocking as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b5b81d8a8d
commit
b7be8d492a
1 file changed
+12
-1
@@ -174,7 +174,12 @@ function createSourceFileCleanup(options) {
|
||||
const canonicalFile = canonicalize(input.file);
|
||||
const manifest = createManifest(input, canonicalFile);
|
||||
const leaseToken = leases.get(canonicalFile);
|
||||
if (leaseToken && leaseToken !== token) {
|
||||
const previousOwner = leaseToken && leaseToken !== token ? groups.get(leaseToken) : null;
|
||||
if (previousOwner && previousOwner.canonicalFile === canonicalFile && canBeSuperseded(previousOwner)) {
|
||||
previousOwner.registrationOutcome = previousOwner.registrationOutcome || 'superseded';
|
||||
leases.set(canonicalFile, token);
|
||||
await inspectRegistration(manifest);
|
||||
} else if (leaseToken && leaseToken !== token) {
|
||||
manifest.registrationOutcome = 'blocked';
|
||||
manifest.registrationError = new Error('active-source-lease');
|
||||
const leaseOwner = groups.get(leaseToken);
|
||||
@@ -208,6 +213,12 @@ function createSourceFileCleanup(options) {
|
||||
return true;
|
||||
}
|
||||
|
||||
function canBeSuperseded(manifest) {
|
||||
return !manifest.finalizationPromise
|
||||
&& manifest.jobs.size > 0
|
||||
&& [...manifest.jobs.values()].every((job) => job.status !== 'pending');
|
||||
}
|
||||
|
||||
function isReady(manifest) {
|
||||
return !manifest.finalizationPromise
|
||||
&& !manifest.registrationOutcome
|
||||
|
||||
Reference in new issue
Block a user