Search code examples
firebasegoogle-cloud-platformgoogle-tasksgoogle-cloud-tasks

Google Cloud RunTask before its scheduled to run


When using Google Cloud Tasks, how can i prematurely run a tasks that is in the queue. I have a need to run the task before it's scheduled to run. For example the user chooses to navigate away from the page and they are prompted. If they accept the prompt to move away from that page, i need to clear the queued task item programmatically.

I will be running this with a firebase-function on the backend.


Solution

  • Looking at the API for Cloud Tasks found here it seems we have primitives to:

    • list - get a list of tasks that are queued to run
    • delete - delete a task this is queued to run
    • run - forces a task to run now

    Based on these primitives, we seem to have all the "bits" necessary to achieve your ask.

    For example:

    To run a task now that is scheduled to run in the future.

    1. List all the tasks
    2. Find the task that you want to run now
    3. Delete the task
    4. Run a task (now) using the details of the retrieved task

    We appear to have a REST API as well as language bound libraries for the popular languages.