From 5a80534b3fc3c885ec56afe9ca48b4c4c327b4bf Mon Sep 17 00:00:00 2001 From: Convly Date: Fri, 24 Feb 2023 15:18:35 +0100 Subject: [PATCH] Gracefully end the transfer --- .../providers/remote-destination/index.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/packages/core/data-transfer/src/strapi/providers/remote-destination/index.ts b/packages/core/data-transfer/src/strapi/providers/remote-destination/index.ts index bb7e1d7500..9bf3afaa12 100644 --- a/packages/core/data-transfer/src/strapi/providers/remote-destination/index.ts +++ b/packages/core/data-transfer/src/strapi/providers/remote-destination/index.ts @@ -41,10 +41,13 @@ class RemoteStrapiDestinationProvider implements IDestinationProvider { dispatcher: ReturnType | null; + transferID: string | null; + constructor(options: IRemoteStrapiDestinationProviderOptions) { this.options = options; this.ws = null; this.dispatcher = null; + this.transferID = null; } async initTransfer(): Promise { @@ -176,15 +179,23 @@ class RemoteStrapiDestinationProvider implements IDestinationProvider { this.ws = ws; this.dispatcher = createDispatcher(this.ws); - const transferID = await this.initTransfer(); + this.transferID = await this.initTransfer(); - this.dispatcher.setTransferProperties({ id: transferID, kind: 'push' }); + this.dispatcher.setTransferProperties({ id: this.transferID, kind: 'push' }); await this.dispatcher.dispatchTransferAction('bootstrap'); } async close() { - await this.dispatcher?.dispatchTransferAction('close'); + // Gracefully close the remote transfer process + if (this.transferID && this.dispatcher) { + await this.dispatcher.dispatchTransferAction('close'); + + await this.dispatcher.dispatchCommand({ + command: 'end', + params: { transferID: this.transferID }, + }); + } await new Promise((resolve) => { const { ws } = this;