uber / cadence

Cadence is a distributed, scalable, durable, and highly available orchestration engine to execute asynchronous long-running business logic in a scalable and resilient way.
https://cadenceworkflow.io
MIT License
8.27k stars 797 forks source link

Orchestrator example with workflow status? #3563

Open ianthpun opened 4 years ago

ianthpun commented 4 years ago

I've been trying to find an example similar expenses where we integrate multiple services in a workflow, but there is a way for us to follow the workflow status.

For example, say a user wants to make a purchase, an example work flow would be:

1) DebitUserActivity 2) RemoveStoreStockActivity

Assuming theres two different services (User service and store service), say I'd like to know where I am in the workflow from the front end. I am aware there is a query you can call on the workflow ID but what if we wanted our own status names? For example, returning something like PENDING, or DEBITED_USER, etc.

Would that mean the workflow itself needs to hit another service who's responsibility is to manage the statuses of the workflow? Ex:

1) DebitUserActivity 2) UpdatePuchaseStatusActivity 3) RemoveStoreStockActivity 4) UpdatePurchaseStatusActivity ... ...

Thanks!

longquanzheng commented 4 years ago

but what if we wanted our own status names? For example, returning something like PENDING, or DEBITED_USER

The query result is up to your workflow query handler. You could make return status in any structure. If you have a local variable with values PENDING | DEBITED_USER, then you should be able to return the value as long as you return it in the query handler function.

But maybe I misunderstood your problem, do you mean that the workflow is only able to know DebitUserActivity is done, but can't get the PENDING status because it's managed by the User service, is that correct?

ianthpun commented 4 years ago

I'm looking at the application similar to how Maxim explains the use case here:

image in https://www.youtube.com/watch?v=llmsBGKOuWI&t=468s .

So if we converted that into a cadence workflow, I believe it is like:

// starting status = // PENDING
debitRider()
updateDb(status) // DEBITED_DRIVER 
creditDriver()
updateDb(status) // FULLY_PROCESSED

However, Maxim seems to imply that the updateDb is not necessary, as seen here:

image

But if thats the case, how do we get our custom statuses such as PENDING/DEBITED_DRIVER/FULLY_PROCESSED?

meiliang86 commented 3 years ago

You can maintain your state inside your workflow as local variable. Use signal handler to change the state, and use query handler to get the state from outside of your workflow.