Building a swap between 2 workers, and looking for a way to rename a worker through the CF API

Hey :slightly_smiling_face: ,
i am trying to build a swap mechanism. 1 domain, 2 workers - staging and production.
so a deploy process would be

  1. shipping my worker script into 1 worker - let’s name it “staging”.
  2. smoke test by pinging this worker and check it’s availability.
  3. switching the route of the domain to this staging worker.
  4. change the previous production worker name to “staging” and the staging name to “production”

can’t find a better way of doing it, neither an API of cloudflare i can use to rename the worker

You might create a worker online that makes the swap.

  1. download the production worker in a variable
  2. send the new worker under the name ‘production’
  3. send the old worker under the name ‘staging’

Hey,
if i get it right, this way it is another deployment of a worker script which i prefer to avoid.
if the initial deployment to a staging worker went smooth, i just need to swap between these two, because i know for sure the staging worker is up and running, and should remain “untouched”, besides (changing the worker name)
otherwise, something can get wrong on the second deployment, like env variables and stuff during the deploy process.
trying to reduce the risk of a bad deployment to 0 :sweat_smile:

Key : worker’s name
Value : worker’s content

Unless a special API exists, I suppose you can’t swap names/values without a PUT and an intermediary/temporary variable.

But is the uploaded worker’s name so important ?
If you change routes it shall work.
And changing routes means you can generate any worker name, just like an id / hash / date.
Do you really need to call your workers staging and production ?
Can’t you store this information otherwhise, like { staging : stagingWorkerId, prod : prodWorkerId }

hmm interesting idea
it is making the “swap back” process a bit more complicated, because the idea is to also have the ability of quick swapping back. so if the “older” deployment isn’t called staging, for example, it will be called “my-worker-script-v1.0.1” then i’ll need to fetch this name from somewhere or keep a mapping of previous released somewhere outside of cloudfalre.
and this way also requires an API to change a route to a different worker without a worker script deployment