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
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.
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?
We are talking about two separate workflows here. There is no reason to engineer with pause or not.
Initiate and go up until you fire the approval process.
After approval, trigger a new workflow that does the rest of the steps.
Related
So when I submit a braintree order for settlement, there will/can be multiple state changes until I get my money. It can settle, stay in settling, get declined, and so on.
How can I get this information without having to call their API constantly? Is there some kind of webhook for that? Because in my tests, I only get updates for disbursements, which is (if I understood it correctly) basically the last step of the whole transaction.
There are webhooks for some events, but not for specifically when a transaction changes status.
You can, however, use the Search API to create a script or cron job that checks for status changes over a period of time.
If you have additional questions about webhooks or using the API, contact Support.
Intro
Hey, my question is kind of hard to explain so I apologize in advance.
Question
I'm trying to implement microservices for our ecommerce and I'm having issues on how to respond to a request when the actual logic and data needs to be determined by other ( 2-3 ) services.
In order to make it easier to understand, I'll give an example.
Lets say User A is trying to buy a product. after clicking on "check out" button these steps should happen.
Flow
Request comes in:
Ecommerce service:
Check if product has enough quantity in inventory.
Publish an event indicating a new order has been created. order:created
Anti Fraud service:
Receives order:created and checks whether the user is a fraud or not
Publishes an event indicating the check was successful. check:succeed
Payment Service:
Receives check:succeed and creates a url to the gateway.
Sends the gateway url to the user. (( this is where the question arises ))
Since all of these steps are asynchronous, how do I respond to the request?
Possible Solution
After the user has requested to checkout, the ecommerce service creates an order and responds immediately with the orderId of newly created order, on client-side the user has to request periodically and check whether the status of order is PENDING PAYMENT, in order to achieve this, the payment service needs to publish payment:created after the order has been approved by the system and then ecommerce service can update the order.
My solution works, but I'm really new to microservices and I want to ask from experts like you on how to implement this in a better way.
I really appreciate if you read this far, Thank you for your time.
your flow is a synchronous process. you need a result from previous step so it has to go step by step.
point of system view:
what matters here is: "how to handle steps?". which reminds me SAGA design pattern (specially when you need a rollback handling) but in general there are two types (choreography and orchestration). The choreography describes the interactions between multiple services, where as orchestration represents control from one party's perspective.
for simplicity you can implement the command pattern or use EAI(Enterprise Application Integration) tools like Apache camel to handle message between endpoints according to the flow.
if you have a lots of visitors it's also better to use a queue between endpoints whether with an orchestrator or without.
point of user view:
when a user click to checkout their cart. they don't expect many of steps or to do more than just wait. as keeping the connection open for response is not a good idea maybe a loader and a periodically ajax call behind it is quite enough while there are other solutions like push notification (then you can consider on fire and forget mechanism).
Your workflow for handling a request as it is defined is totally synchronous. Each step depends on the previous step, and cannot start until it finishes. However, second step does not seem to need data from the first step, so actually they could be executed in parallel.
so, what can be done is start both of them:
Check if product has enough quantity in inventory.
Checks whether the user is a fraud or not
then
wait for response and if both are ok, then creates a url to the gateway. and sends it to the user.
You can create a camel route or any other tool that implements EIP to achieve the functionality
I am working with a test action that when activated and called via javascript will fire an email message. I used an action because I wanted to pass in some values to be used in the process. In a traditional workflow I could see the history of each time the workflow was fired.
Is there a way to see all of the times my custom action fired?
Traditional workflow are Asynchronous. What you are seeing as Process Sessions are actually Async Execution logs. Those are not available/applicable for Sync jobs like Realtime workflows or Actions. Maybe you can keep the failure logs in Action.
Unfortunately you have to assume from the Emails that sent out is Action execution time.
We are integrating with SagePay using the server integration method.
The notification POST from SagePay calls back to a PHP script our side.
Our PHP callback itself has to call several methods on an external webservice.
Sometimes, due to network latency, our callback script takes over 20 seconds to run. SagePay doesn't like this and reissues a new notification POST. This results in our callback ultimately running twice, or more, which is less than ideal (sends out multiple payment complete emails etc). Basically SagePay keeps issuing notifications until it gets a response in less than 20 seconds.
We can't just ignore the latest POST request from SagePay as they 'forget' about any previous notifications and look to receive a response from the most recent one. We can't do anything about network latency either.
Does anyone have any advice on what to do in such a situation?
The first thing your Notification callback could do is to check the transaction table and if not already updated then update the transaction table with the message and continue with your business processing, or else discard the repeated call. I wasn't aware that Sagepay only accepted a response from the most recently issued Notification callback, and this isn't mentioned in the integration guide.
You should still aim to speed it up, however. Have a think about how you might send your emails in a cron/scheduled job every minute, so that your customers are not held-up waiting for your third parties to respond. Rather than sending emails in your Notification callback you can simply add rows to an email_queue table, to be processed later by the cron job.
I'm working with the the Release Candidate of Visual Studio 2010 using Wf4 to write a new workflow for approving resource requests. In my workflow, I would like for a request to expire after a few days if no approval has been made for the request. We did this in WF 3.5 (Visual Studio 2008) by adding a Delay timer into an EventDrivenActivity parallel to the EventDrivenActivity that was awaiting an approver to come and approve the request. If the Delay expired before an approval was made, the EventDrivenActivity would terminate the request. Does anyone know if there is a similar mechanism for doing this in WF4?
In WF4 this is done in the same way using a Pick activity. A Pick has multiple PickBranch children, each with a Trigger and an Action. The Trigger for each is executed and will contain the Delay, Receive or whatever else you are waiting for. The Action than contains whatever needs to be executed. Only the Action associated with the first Trigger to complete is executed, the other triggers will be canceled and the other actions skipped.