diff --git a/shared/packages/worker/src/worker/accessorHandlers/atem.ts b/shared/packages/worker/src/worker/accessorHandlers/atem.ts index 9339a7d6..a8b1a913 100644 --- a/shared/packages/worker/src/worker/accessorHandlers/atem.ts +++ b/shared/packages/worker/src/worker/accessorHandlers/atem.ts @@ -206,13 +206,15 @@ export class ATEMAccessorHandle extends GenericAccessorHandle { + async removePackage(reason: string): Promise { const atem = await this.getAtem() if (this.accessor.mediaType && typeof this.accessor.bankIndex === 'number') { if (this.accessor.mediaType === 'clip') { await atem.clearMediaPoolClip(this.accessor.bankIndex) + this.worker.logOperation(`Remove package: Removed clip "${this.packageName}" (${reason})`) } else { await atem.clearMediaPoolStill(this.accessor.bankIndex) + this.worker.logOperation(`Remove package: Removed still "${this.packageName}" (${reason})`) } } else { throw new Error('mediaType or bankIndex were undefined') diff --git a/shared/packages/worker/src/worker/accessorHandlers/fileShare.ts b/shared/packages/worker/src/worker/accessorHandlers/fileShare.ts index 02c2776b..c06bc234 100644 --- a/shared/packages/worker/src/worker/accessorHandlers/fileShare.ts +++ b/shared/packages/worker/src/worker/accessorHandlers/fileShare.ts @@ -228,11 +228,17 @@ export class FileShareAccessorHandle extends GenericFileAccessorHandle async removePackage(reason: string): Promise { await this.prepareFileAccess() if (this.workOptions.removeDelay) { + this.worker.logOperation( + `Remove package: Delay remove file "${this.packageName}", delay: ${this.workOptions.removeDelay} (${reason})` + ) await this.delayPackageRemoval(this.filePath, this.workOptions.removeDelay) } else { await this.removeMetadata() - if (await this.unlinkIfExists(this.fullPath)) + if (await this.unlinkIfExists(this.fullPath)) { this.worker.logOperation(`Remove package: Removed file "${this.packageName}", ${reason}`) + } else { + this.worker.logOperation(`Remove package: File already removed "${this.packageName}" (${reason})`) + } } } diff --git a/shared/packages/worker/src/worker/accessorHandlers/http.ts b/shared/packages/worker/src/worker/accessorHandlers/http.ts index fd73ad6f..2f29266e 100644 --- a/shared/packages/worker/src/worker/accessorHandlers/http.ts +++ b/shared/packages/worker/src/worker/accessorHandlers/http.ts @@ -101,12 +101,19 @@ export class HTTPAccessorHandle extends GenericAccessorHandle { + async removePackage(reason: string): Promise { if (this.workOptions.removeDelay) { await this.delayPackageRemoval(this.workOptions.removeDelay) + this.worker.logOperation( + `Remove package: Delay remove package "${this.packageName}", delay: ${this.workOptions.removeDelay} (${reason})` + ) } else { await this.removeMetadata() - await this.deletePackageIfExists(this.fullUrl) + if (await this.deletePackageIfExists(this.fullUrl)) { + this.worker.logOperation(`Remove package: Removed file "${this.packageName}" (${reason})`) + } else { + this.worker.logOperation(`Remove package: File already removed "${this.packageName}" (${reason})`) + } } } async getPackageReadStream(): Promise { @@ -361,17 +368,19 @@ export class HTTPAccessorHandle extends GenericAccessorHandle { + /** Returns false if it doesn't exist */ + private async deletePackageIfExists(url: string): Promise { const result = await fetchWithTimeout(url, { method: 'DELETE', }) - if (result.status === 404) return undefined // that's ok + if (result.status === 404) return false // that's ok if (result.status >= 400) { const text = await result.text() throw new Error( `deletePackageIfExists: Bad response: [${result.status}]: ${result.statusText}, DELETE ${this.fullUrl}, ${text}` ) } + return true } /** Full path to the file containing deferred removals */ private get deferRemovePackagesPath(): string { diff --git a/shared/packages/worker/src/worker/accessorHandlers/httpProxy.ts b/shared/packages/worker/src/worker/accessorHandlers/httpProxy.ts index 614b3679..f38b6c7d 100644 --- a/shared/packages/worker/src/worker/accessorHandlers/httpProxy.ts +++ b/shared/packages/worker/src/worker/accessorHandlers/httpProxy.ts @@ -100,12 +100,19 @@ export class HTTPProxyAccessorHandle extends GenericAccessorHandle { + async removePackage(reason: string): Promise { if (this.workOptions.removeDelay) { - await this.delayPackageRemoval(this.workOptions.removeDelay) + this.worker.logOperation( + `Remove package: Delay remove package "${this.packageName}", delay: ${this.workOptions.removeDelay} (${reason})` + ) + await this.delayPackageRemoval(this.filePath, this.workOptions.removeDelay) } else { await this.removeMetadata() - await this.deletePackageIfExists(this.fullUrl) + if (await this.deletePackageIfExists(this.fullUrl)) { + this.worker.logOperation(`Remove package: Removed file "${this.packageName}" (${reason})`) + } else { + this.worker.logOperation(`Remove package: File already removed "${this.packageName}" (${reason})`) + } } } async getPackageReadStream(): Promise { @@ -297,11 +304,9 @@ export class HTTPProxyAccessorHandle extends GenericAccessorHandle { + async delayPackageRemoval(filePath: string, ttl: number): Promise { const packagesToRemove = await this.getPackagesToRemove() - const filePath = this.filePath - // Search for a pre-existing entry: let found = false for (const entry of packagesToRemove) { @@ -375,17 +380,19 @@ export class HTTPProxyAccessorHandle extends GenericAccessorHandle { + /** Returns false if nothing was removed */ + private async deletePackageIfExists(url: string): Promise { const result = await fetchWithTimeout(url, { method: 'DELETE', }) - if (result.status === 404) return undefined // that's ok + if (result.status === 404) return false // that's ok if (result.status >= 400) { const text = await result.text() throw new Error( `deletePackageIfExists: Bad response: [${result.status}]: ${result.statusText}, DELETE ${this.fullUrl}, ${text}` ) } + return true } /** Full path to the file containing deferred removals */ private get deferRemovePackagesPath(): string { diff --git a/shared/packages/worker/src/worker/accessorHandlers/localFolder.ts b/shared/packages/worker/src/worker/accessorHandlers/localFolder.ts index deef5333..3e559d47 100644 --- a/shared/packages/worker/src/worker/accessorHandlers/localFolder.ts +++ b/shared/packages/worker/src/worker/accessorHandlers/localFolder.ts @@ -180,11 +180,17 @@ export class LocalFolderAccessorHandle extends GenericFileAccessorHand } async removePackage(reason: string): Promise { if (this.workOptions.removeDelay) { + this.worker.logOperation( + `Remove package: Delay remove file "${this.packageName}", delay: ${this.workOptions.removeDelay} (${reason})` + ) await this.delayPackageRemoval(this.filePath, this.workOptions.removeDelay) } else { await this.removeMetadata() - if (await this.unlinkIfExists(this.fullPath)) - this.worker.logOperation(`Remove package: Removed file "${this.fullPath}" (${reason})`) + if (await this.unlinkIfExists(this.fullPath)) { + this.worker.logOperation(`Remove package: Removed file "${this.packageName}" (${reason})`) + } else { + this.worker.logOperation(`Remove package: File already removed "${this.packageName}" (${reason})`) + } } } async getPackageReadStream(): Promise<{ readStream: NodeJS.ReadableStream; cancel: () => void }> {