You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The activity completion, often a cancel failure as result of worker shutdown, may not get recorded before run/shutdown returns. This becomes evident if you sys.exit() immediately after shutdown returns.
Minimal Reproduction
importasyncioimportloggingimportsignalimportsysimportosfromdatetimeimporttimedeltafromuuidimportuuid4fromtemporalioimportactivity, workflowfromtemporalio.clientimportClientfromtemporalio.commonimportRetryPolicyfromtemporalio.workerimportWorkerasyncdefhandler_stop_signals():
shutdowns= []
shutdowns.append(worker.shutdown())
awaitasyncio.gather(*shutdowns)
sys.exit()
@activity.defnasyncdeflong_activity() ->None:
activity.logger.info(
f"Activity waiting for cancel, attempt: {activity.info().attempt}"
)
awaitasyncio.sleep(60)
@workflow.defnclassMyWorkflow:
@workflow.runasyncdefrun(self):
awaitworkflow.execute_activity(
long_activity,
start_to_close_timeout=timedelta(hours=2),
retry_policy=RetryPolicy(maximum_attempts=1),
)
asyncdefmain():
logging.basicConfig(level=logging.INFO)
logging.info("Starting worker")
client=awaitClient.connect("localhost:7233")
task_queue=f"tq-{uuid4()}"globalworkerworker=Worker(
client,
task_queue=task_queue,
workflows=[MyWorkflow],
activities=[long_activity],
graceful_shutdown_timeout=timedelta(minutes=24),
)
loop=asyncio.get_event_loop()
run_task=asyncio.create_task(worker.run())
logging.info("Starting workflow")
handle=awaitclient.start_workflow(
MyWorkflow.run,
id=f"wf-{uuid4()}",
task_queue=task_queue,
)
logging.info("Started workflow with ID %s"%handle.id)
logging.info(os.getpid())
logging.info("Waiting for SIGTERM")
loop.add_signal_handler(signal.SIGTERM, lambda: asyncio.ensure_future(handler_stop_signals()))
awaitrun_tasklogging.info(
"Worker shutdown, activity will fail, but workflow will remain until a worker is available to process failure"
)
if__name__=="__main__":
asyncio.run(main())
Sometimes this doesn't record the activity failure sometimes it does. We need to properly finish running activities before closing activity worker (we thought we were but looking at code, running activity completion may not get recorded).
The text was updated successfully, but these errors were encountered:
Describe the bug
The activity completion, often a cancel failure as result of worker shutdown, may not get recorded before run/shutdown returns. This becomes evident if you
sys.exit()
immediately after shutdown returns.Minimal Reproduction
Sometimes this doesn't record the activity failure sometimes it does. We need to properly finish running activities before closing activity worker (we thought we were but looking at code, running activity completion may not get recorded).
The text was updated successfully, but these errors were encountered: