firebase-tools icon indicating copy to clipboard operation
firebase-tools copied to clipboard

fix: prevent failure when deleting cloud function with missing schedule

Open crossan007 opened this issue 1 year ago • 3 comments

Closes: 4795

Description

Fixes https://github.com/firebase/firebase-tools/issues/4795#issuecomment-2393788829

When deletion of a pubsub.schedule Cloud Function partially fails, manual interaction is required to fully delete the function.

In my case, deletion of the Cloud Function was unpredictably failing after deleting the associated Cloud Schedule, leaving the function unable to be deleted by a deployment even with the --force CLI flag

This MR changes the behavior of Cloud Functions deployment so that a function which is supposed to have an associated schedule will be deleted if the schedule no longer exists.

Scenarios Tested

Using the latest build of master @ a54e4ff20cc0aca11d89e2f6b31c35f063918d87

  1. Deploy a Cloud Function (v1) using firebase deploy
  2. Confirm the function exists https://console.cloud.google.com/functions/list
  3. Confirm the schedule for the function exists https://console.cloud.google.com/cloudscheduler
  4. Delete the schedule associated with the function a. I am unsure what specific scenarios cause the schedule to be deleted without the function being deleted, but it's happened to me a number of times b. Notice the Trigger column in the Firebase console becomes blank: 373668886-11645a9a-b9ee-44e5-a496-d60816517304
  5. Remove the function from the deployment source code
  6. Run firebase deploy a. Observe the failure in the deploy logs: HTTP Error: 404, Job not found. b. Observe the final failure notice in the deploy logs:
    Error: There was an error deploying functions:
      Error Failed to upsert schedule function <function name> in region us-central1
    

Using the changes from this merge request

repeat steps 1-5

  1. Run firebase deploy a. Observe the warning in the deploy logs:
    HTTP Error: 404, Job not found.
    Trigger for dispatchCampaign not found, continuing with deletion of function
    
    b. Confirm the deployment succeeds and the affected functions have been removed.

Sample Commands

crossan007 avatar Oct 04 '24 16:10 crossan007

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

google-cla[bot] avatar Oct 04 '24 16:10 google-cla[bot]

@taeold and @christhompsongoogle are tagged in the associated issue

crossan007 avatar Oct 04 '24 16:10 crossan007

Fixes #4795

joehan avatar Oct 08 '24 17:10 joehan