Hi Prefect, Is there a way to create a custom Tas...
# ask-community
p
Hi Prefect, Is there a way to create a custom Task that can be visualized in the Prefect UI similar to Parameter tasks? I currently get most of my parameter variables from environment variables being set (and want to continue doing this). Ideally I want to group related parameters into groups (e.g. by using data classes) so the resulting groups can be passed around to wherever they are needed. For example, I currently fetch my parameters to communicate with my Kafka service via this custom task:
Copy code
class GetKafkaConfig(prefect.Task):
    """
    Get Kafka configuration
    """
    def run(
                self,
                timeout: timedelta
            ) -> KafkaConfig:
        return KafkaConfig(
            broker_address=os.environ['KAFKA_BROKER_ADDRESS'],
            topic_name=os.environ['KAFKA_TOPIC_NAME'],
            timeout=timeout
        )
I would like to visualize these parameters in my prefect UI (and ideally make them editable), similar to how Parameter tasks can be visualized (e.g. as is demonstrated in

https://docs.prefect.io/orchestration/tutorial/hello-flow-run-parameter-config.png

) Is it possible to write custom visualization layers for custom Tasks?
k
Hi @Peter Roelants! Unfortunately, this is not possible. The most you can do is pass dictionaries as Parameters for them to get to the UI. I’ll show this use case to the team though.
p
I tried the json/dictionary approach, however it is not compatible with reading a group of parameters from the environment (unless they are stored as json in a single environment variable). I was hoping it would be as simple as writing a custom serialization layer or something. If it's not possible, don't worry, it's a low priority use case to us.
k
I see what you mean, You can open a feature request if you’re interested. Sorry about that!
p
👍 1