Sync wait a workflow

Hi, i am new to Temporal! I am assigned to do investigation on temporal.
after some study still need some help from community!

not sure if this can be done in temporal.
I have a 3rd-party payment workflow.

  1. Fire 3rd-party API for payment
  2. wait for payment(they callback to our server).
  3. start delivering goods…

Is it possible to start new workflow and wait for the first activity’s result with sync waiting?

def request_handler
  Temporal.start_workflow(PaymentWorkflow, user_id: "john0123", amount: 200)
  # response based on success or failure of first activity
end

I see query interface concept in doc. But I still need to poll for it.
And it’s not promised that our workers are fast enough to run the first activity. I can indeed take 3rd api call out of workflow. But placing the activity in workflow is more clear.

I would like to know the best practice to handle this use case.

If I understand you correctly, you can try the proxy workflow pattern, e.g.

  1. Start proxy workflow
  2. Proxy workflow starts main workflow, and waits for a signal
  3. Main workflow fires 3rd-party API for payment
  4. After (3) is done, the main workflow signals the proxy workflow
  5. Proxy workflow completes while main workflow still continues

This way you can execute the proxy workflow synchronously, and have the rest of your business logic continue.

Alternatively, as you mentioned, you can include the status in your workflow state, and poll query for it.

thanks a lot. clear enough for me. not sure if temporal-ruby can do it

Yes, this pattern is not SDK specific.

indeed, it’s not related to SDK. but it still require the sdk to complete implement signaling SignalWorkflowExecution.
Like QueryWorkflow is not finished yet in temporal-ruby

You can query workflow using rRPC interface directly. I would be surprised if calling gRPC methods is not supported.

Thanks a lot @mrsaint, @maxim

I think for early terminating proxy workflow, we need to change parent close policy to abandon children.
I can now implement it successfully.