Skip to content

Commit

Permalink
feat(handler): add index field to support chained handlers
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mostaphaRoudsari committed May 26, 2021
1 parent 9a68700 commit 325f6be
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions queenbee/io/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
)

0 comments on commit 325f6be

Please sign in to comment.