Is there a way to pause an execution of a workflow?

894 views Asked by At

Is there a way to pauses and resumes a workflow programmatically through the REST API? For instance, I would like to be able to submit a personal time off request from an app, the app creates and triggers a workflow. The workflow sends a notification to the manager for approval and the workflow execution is paused while waiting for the manager's approval. Once the manager approves the request, it calls the workflow API to resumes the execution of the workflow.

From the documentation, there's an option to put the workflow to sleep and I can use it to periodically check for the request's status but this incurs additional cost because there's no idea when the manager is going to approve the request.

https://cloud.google.com/workflows/docs/reference/syntax

3

There are 3 answers

5
Kris Braun On BEST ANSWER

Update 2021-10-05:

Waiting for an HTTP callback is now supported:

    - create_callback:
        call: events.create_callback_endpoint
        args:
            http_callback_method: POST # can be GET, PUT, ...
        result: callback_details
    # Send the callback URL somewhere for another service to call
    - await_callback:
        call: events.await_callback
        args:
            callback: ${callback_details}
            timeout: 1800 # optional, in seconds
        result: callback_request

Original response

The ability to wait for an HTTP webhook callback during a workflow execution is planned. (I'm the Workflows PM.)

Until then, you're right that the best solution is to poll for a flag (Firestore works well for this) using sleep.

2
Pentium10 On

We are talking about two separate workflows here. There is no reason to engineer with pause or not.

  1. Initiate and go up until you fire the approval process.
  2. After approval, trigger a new workflow that does the rest of the steps.
1
paradox On

Not sure about your use-case, but I guess you can only choose to execute the workflow once the manager has approved.

As you know there are 2 parts the first part creates the workflow. As it is in https://cloud.google.com/workflows/docs/reference/rest/v1beta/projects.locations.workflows/create api for example. Or you can look at https://cloud.google.com/workflows/docs/creating-updating-workflow.

That does not execute the workflow it just creates it. So it can be executed at a later stage.

To execute the workflow, there is this Api https://cloud.google.com/workflows/docs/reference/executions/rest/v1beta/projects.locations.workflows.executions/create OR see https://cloud.google.com/workflows/docs/executing-workflow

Also when executing the workflow you can pass in parameters if needed.

Then If I understand the pricing correctly from https://cloud.google.com/workflows#section-9 it seems they only charge you per step executed.

Sorry, I have been through those docs a fair amount I did not see an "option to put the workflow to sleep", Could you link those docs by any chance?