Alexander van Eck
09/27/2021, 5:14 PMdef cancel(obj: Union[Task, Flow], _: State, new_state: State) -> State:
if isinstance(new_state, (Cancelling, Cancelled)):
obj.some_arg.cancel() # let them know we're no longer waiting
return new_state
class RemoteTask(Task):
def __init__(self, *args: Any, **kwargs: Any) -> None:
state_handlers = kwargs.pop('state_handlers', [])
state_handlers.append(cancel)
kwargs['state_handlers'] = state_handlers
super().__init__(*args, **kwargs)
Kevin Kho
09/27/2021, 5:23 PMAlexander van Eck
09/27/2021, 5:43 PMKevin Kho
09/27/2021, 5:49 PMAlexander van Eck
09/27/2021, 9:31 PMCloudFlowRunner.check_for_cancellation.interrupt_if_cancelling
throws back to the main thread should be responded to somehow by the main thread and go over all tasks to call their state_handler?Kevin Kho
09/27/2021, 9:32 PMAlexander van Eck
09/27/2021, 9:36 PMKevin Kho
09/27/2021, 9:36 PMAlexander van Eck
09/28/2021, 7:22 AMfinally
clause?
@task
def long_running_task():
response = <http://request.post|request.post>(...) # start long running job
try:
while True:
status = request.get(...).body # check if job is done
if status == 'ok':
break
sleep(10)
finally:
request.delete(...) # tell job to stop running
Kevin Kho
10/06/2021, 1:30 PMAlexander van Eck
10/07/2021, 12:54 PMKevin Kho
10/07/2021, 1:55 PM