In this example, you will see how dataclasses are used to represent input and output data of Workflow and Activity Definitions.
If you haven't already started the Translation Microservice used by this exercise, do so in a separate terminal.
- Ensure that the virtual environment you setup at the beginning of the course is activated as detailed in the course README
- Navigate to the
utilitiesdirectory at the root level of the course - Change directories into the
microservicedirectorycd utilities/microservice
- Run the microservice
python microservice.py
This sample provides an improved version of the translation Workflow used in Temporal 101. The Workflow follows the best practice of using objects to represent input parameters and return values.
Look at the code in the shared.py file to see how the objects are defined for
the Workflows and Activities. After this, look at the workflow.py file to see
how these values are passed in and used in the Workflow code. Finally, look at
starter.py to see how the input parameters are created and passed into the Workflow.
Now let's take a look at how we used objects to represent input and output data in Activity definitions.
Take a look at the activities.py file to see how the translate_term method
takes in the TranslationActivityInput dataclass as an input parameter. Also
notice how that method returns a TranslationActivityOutput object for the output.
To run the workflow
- In one terminal, start the Worker by running
python worker.py - In another terminal, execute the Workflow by running
python starter.py Mason fr(replaceMasonwith your first name), which should display customized greeting and farewell messages in French.
It's common for a single Workflow Definition to be executed multiple times, each time using a different input. Feel free to experiment with this by specifying a different language code when starting the Workflow. The translation service currently supports the following languages:
de: Germanes: Spanishfr: Frenchlv: Latvianmi: Maorisk: Slovaktr: Turkishzu: Zulu