From 325f6bee1c853cd0bc868ef22e27328c8a16d7c1 Mon Sep 17 00:00:00 2001 From: mostaphaRoudsari Date: Wed, 26 May 2021 17:50:26 -0400 Subject: [PATCH] feat(handler): add index field to support chained handlers One of the creative usage of handlers that [came up](https://github.com/pollination/pollination-alias/blob/21a0db5569c739cfb4f0de6a1dc8b3f1721bfd4c/pollination/alias/outputs/daylight.py#L25-L38) during the development was to use handlers one after another. Luckily the current schema could support this case: ```python OutputAlias.linked( name='results', platform=['rhino'], handler=[ # Preload results IOAliasHandler( language='python', module='pollination_handlers.outputs.daylight', function='read_df_from_folder' ), # load preloaded outputs to Rhino with following method IOAliasHandler( language='csharp', module='Pollination.RhinoHandlers', function='LoadMeshBasedResultsToRhino' ) ] ) ``` The current implementation doesn't indicate which handler should be executed first. In this case since @MingboPeng was the developer of both the Rhino plugin and the Alias he knew how to get it to work but it wouldn't work otherwise. This commit adds an optional index field to IOALiasHandler object to support supporting chained handlers. Default value will be set to 0. That means the code above will look like this: ```python OutputAlias.linked( name='results', platform=['rhino'], handler=[ # Preload results IOAliasHandler( language='python', module='pollination_handlers.outputs.daylight', function='read_df_from_folder', index=0 ), # load preloaded outputs to Rhino with following method IOAliasHandler( language='csharp', module='Pollination.RhinoHandlers', function='LoadMeshBasedResultsToRhino', index=1 ) ] ) ``` This change will make it explicit that the Rhino platform should use the first handler for reading the results and execute that in Python - then pass the results to the second handler and run that one in C# which is the intended behavior. --- queenbee/io/common.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/queenbee/io/common.py b/queenbee/io/common.py index bfc9f74e..0108a1fa 100644 --- a/queenbee/io/common.py +++ b/queenbee/io/common.py @@ -410,3 +410,12 @@ class IOAliasHandler(BaseModel): description='Name of the function. The input value will be passed to this ' 'function as the first argument.' ) + + index: int = Field( + 0, + description='An integer to set the index for the order of execution. This input ' + 'is only useful when there are more than one handler for the same platform and ' + 'the output of one handler should be passed to another handler. This is also ' + 'called chained handlers. By default all the handlers are indexed as 0 assuming ' + 'they are not chained.' + )