Temporarily removing timeout with wait

Signed-off-by: Deepanshu Agarwal <deepanshu.agarwal1984@gmail.com>
This commit is contained in:
Deepanshu Agarwal 2023-05-26 16:34:22 +05:30
parent 4bb05a4a03
commit 7aabee0fa2
1 changed files with 8 additions and 6 deletions

View File

@ -3,7 +3,8 @@ from datetime import timedelta
import logging import logging
import json import json
from time import sleep from time import sleep
from dapr.ext.workflow import DaprWorkflowContext, WorkflowActivityContext, when_any from dapr.ext.workflow import DaprWorkflowContext, WorkflowActivityContext
# , when_any
from model import InventoryItem, Notification, InventoryRequest, OrderPayload, OrderResult, PaymentRequest, InventoryResult from model import InventoryItem, Notification, InventoryRequest, OrderPayload, OrderResult, PaymentRequest, InventoryResult
from dapr.clients import DaprClient from dapr.clients import DaprClient
from util import get_address from util import get_address
@ -24,11 +25,12 @@ def order_processing_workflow(ctx: DaprWorkflowContext, orderPayload: OrderPaylo
if orderPayload.total_cost > 50000: if orderPayload.total_cost > 50000:
yield ctx.call_activity(requst_approval_activity, input=orderPayload) yield ctx.call_activity(requst_approval_activity, input=orderPayload)
approval_flag = ctx.wait_for_external_event("manager_approval") approval_flag = ctx.wait_for_external_event("manager_approval")
timeout_event = ctx.create_timer(timedelta(seconds=200)) # Temporarily disabling timeout, as when_any PR is not merged in python-sdk
winner = yield when_any([approval_flag, timeout_event]) # timeout_event = ctx.create_timer(timedelta(seconds=200))
if winner == timeout_event: # winner = yield when_any([approval_flag, timeout_event])
yield ctx.call_activity(notify_activity, input=Notification(message=f'Payment for order {order_id} has been cancelled due to timeout!')) # if winner == timeout_event:
return OrderResult(processed=False) # yield ctx.call_activity(notify_activity, input=Notification(message=f'Payment for order {order_id} has been cancelled due to timeout!'))
# return OrderResult(processed=False)
approval_result = yield approval_flag approval_result = yield approval_flag
if approval_result["approval"]: if approval_result["approval"]:
yield ctx.call_activity(notify_activity, input=Notification(message=f'Payment for order {order_id} has been approved!')) yield ctx.call_activity(notify_activity, input=Notification(message=f'Payment for order {order_id} has been approved!'))