Description
Looking at the fan out fan in example, there are are a few places where we have to manually serialize/deserialize data that we should eliminate.
When call_activity
is called, we automatically serialize the input value to a string (for example, we serialize the int to a str here). However, in the activity function itself, we need to explicitly convert the value back.
When we return a value from an activity, we require manual serialization. And in the orchestrator, we manually deserialize it.
Proposed changes:
- Always deserialize input values for activity functions.
- Always serialize return values for activity functions.
- Always deserialize values returned by the task from
call_activity
(and the othercall_activity
andcall_suborchestrator
variants). - Always serialize input value in
start_new
(looks like we already do this) - Always deserialize
get_input
Some questions:
- What do we do with type hints? (It appears we currently ignore the type hint for an activity function input and always pass a string, as demonstrated here)
- Do we support deserialization to custom classes or stick to primitives like
str
,int
,float
,list
,dict
, etc (whateverjson.loads
supports)?
The changes will allow the orchestrator code to the written like this:
def orchestrator_function(context: df.DurableOrchestrationContext):
activity_list = yield context.call_activity("GetActivityCount", 5)
tasks = [context.call_activity("ParrotValue", i) for i in activity_list]
values = yield context.task_all(tasks)
message = yield context.call_activity("ShowMeTheSum", values)
return message
The activity function would then look like this:
def main(value: int) -> list:
activity_values = [*range(value)]
return activity_values
We should be able to remove all import json
statements from orchestrators and activities except when we're really working with JSON data.