pythonNovice
pythonNovice

Reputation: 1431

Do Google Cloud Tasks Delete themselves once they have executed?

In my application, I have implemented Google Tasks so that my users can receive notifications on when their ToDo item is due.

My main issue is that when my Cloud Task fires, I noticed that I still see it located in my Cloud Task Console. So, do they delete themselves once they are fired? For my application, I want the cloud tasks to delete themselves once they are done.

I noticed in the documentation this line you can also fine-tune the configuration for the task, like scheduling a time in the future when it should be executed or limiting the number of times you want the task to be retried if it fails. The thing is, my task is not failing and yet I see the number of retries at 4.

firebase cloud functions

exports.firestoreTtlCallback = functions.https.onRequest(async (req, res) => {
    try {
        const payload = req.body;
        let entry = await (await admin.firestore().doc(payload.docPath).get()).data();
        let tokens = await (await admin.firestore().doc(`/users/${payload.uid}`).get()).get('tokens')
        await admin.messaging().sendMulticast({
            tokens,
            notification: {
                title: "App",
                body: entry['text']
            }
        }).then((response) => {
            log('Successfully sent message:')
            log(response)
        }).catch((error) => {
            log('Error in sending Message')
            log(error)
        })
        const taskClient = new CloudTasksClient();
        let { expirationTask } = admin.firestore().doc(payload.docPath).get()
        await taskClient.deleteTask({ name: expirationTask })
        await admin.firestore().doc(payload.docPath).update({ expirationTask: admin.firestore.FieldValue.delete() })
        res.status(200)
    } catch (err) {
        log(err)
        res.status(500).send(err)
    }
})

Upvotes: 2

Views: 1307

Answers (1)

Priyashree Bhadra
Priyashree Bhadra

Reputation: 3597

A task can be deleted if it is scheduled or dispatched. A task cannot be deleted if it has completed successfully or permanently failed according to this documentation.

  • The task attempt has succeeded if the app's request handler returns an HTTP response code in the range [200 - 299].
  • The task attempt has failed if the app's handler returns a non-2xx response code or Cloud Tasks does not receive response before the deadline which is :
  1. For HTTP tasks, 10 minutes. The deadline must be in the interval [15 seconds, 30 minutes]

  2. For App Engine tasks, 0 indicates that the request has the default deadline. The default deadline depends on the scaling type of the service: 10 minutes for standard apps with automatic scaling, 24 hours for standard apps with manual and basic scaling, and 60 minutes for flex apps.

  • Failed tasks will be retried according to the retry configuration. Please check your queue.yaml file for the retry configuration set and if you want to specify and set them as per your choice follow this.

The task will be pushed to the worker as an HTTP request. If the worker or the redirected worker acknowledges the task by returning a successful HTTP response code ([200 - 299]), the task will be removed from the queue as per this documentation. If any other HTTP response code is returned or no response is received, the task will be retried according to the following:

  • User-specified throttling: retry configuration, rate limits, and the queue's state.
  • System throttling: To prevent the worker from overloading, Cloud Tasks may temporarily reduce the queue's effective rate. User-specified settings will not be changed.

Upvotes: 1

Related Questions