serverless-cloudflare-workers icon indicating copy to clipboard operation
serverless-cloudflare-workers copied to clipboard

Removal not working due to constructor promise not being returned and the now default multiscript support

Open dietkinnie opened this issue 6 years ago • 0 comments

We are using the serverless-cloudflare-workers plugin and have been deploying our functions to Cloudflare successfully for some time now. Given that the non enterprise accounts, provided the possibility to deploy just to the one worker, we never considered using the Remove functionality provided by this plugin. However, that changed recently when you announced multi script support for all customer (not only Enterprise). Since we wanted to take advantage of this, our CI/CD pipeline was updated to make use of the Serverless remove command, however on doing so, our multi script worker deployments and the respective routes were not being removed.

After numerous hours of debugging it looks like the issue is related to the process of triggering the promise from within the Remove constructor which was not being returned... so the process was exiting since serverless was not then aware that there are additional steps to execute.

diff --git a/node_modules/serverless-cloudflare-workers/remove/cloudflareRemove.js b/node_modules/serverless-cloudflare-workers/remove/cloudflareRemove.js
index 6db2fa8..b1b8e06 100644
--- a/node_modules/serverless-cloudflare-workers/remove/cloudflareRemove.js
+++ b/node_modules/serverless-cloudflare-workers/remove/cloudflareRemove.js
@@ -35,7 +35,7 @@ class CloudflareRemove {
         if (this.options.function || this.options.f) {
           throw new Error("This does not support -f yet.")
         }
-        BB.bind(this)
+        return BB.bind(this)
           .then(this.remove)
           .then(resp => console.log("Removed"))
       }
@@ -50,7 +50,11 @@ class CloudflareRemove {
     } = this.provider.config;
 
     const functionKeys = this.serverless.service.getAllFunctions();
-    const multiscriptEnabled = await this.checkAccountType();
+
+    // Cloudflare enabled multiscripts for everyone. No need to check anything
+    // const multiscriptEnabled = await this.checkAccountType();
+    const multiscriptEnabled = true;
+    

The above patch is relatively crude but ensure that the remove process does indeed work

dietkinnie avatar Jun 07 '19 10:06 dietkinnie