When workflow is cancelled or terminated, in both the cases, temporalio.exceptions.CancelledError is raised.
What’s the difference between cancel and terminate as in both the cases activity is able to perform a cleanup?
PS: Activity I have implemented are sync python activities, worker is instantiated with activity_executor in order to run non-async activities, and worker graceful timeout is set to a very high duration…
Termination is a hard stop of a workflow, not the worker. Please provide more information about what exactly is happening. Workflow history would help.
def run(self):
try:
for pct in range(0, 100, 1):
activity.heartbeat(pct)
# below sleep is similar to grpc/any client/database call
# PS: time.sleep() is used just to emulate network/blocking calls, we should refrain from using sleep
time.sleep(0.5)
except CancelledError as ce:
LOG.info(f'Received the error, {type(ce)}')
# reraising the exception
raise ce
Terminating workflow (or completing it any other way) cancels all its activities. Cancellation gives the workflow an ability to perform whatever business logic is needed for cleanup.