This tutorial covers the implementation of the Sagas pattern using Temporal.
To run the example, open four terminal instances and follow the instructions below.
Create a virtual environment:
python3 -m venv venv
Activate your virtual environment:
source .venv/bin/activate
Install the dependencies:
pip install -r requirements.txt
In the first terminal, start the Temporal server in development mode:
temporal server start-dev
In the second terminal, run the worker script:
python run_worker.py
In the third terminal, run the workflow script:
python run_workflow.py
In the fourth terminal, run the following curl
command to initiate a successful booking process.
curl -X POST http://localhost:3002/book \
-H "Content-Type: application/json" \
-d '{
"name": "John Doe",
"attempts": 5,
"car": "valid-car-id",
"hotel": "valid-hotel-id",
"flight": "valid-flight-id"
}'
{
"result": {
"message": {
"booked_car": "valid-car-id",
"booked_flight": "valid-flight-id",
"booked_hotel": "valid-hotel-id"
},
"status": "success"
},
"user_id": "jane-smith-288524"
}
To simulate a booking failure, run the following curl
command in the fourth terminal.
curl -X POST http://localhost:3002/book \
-H "Content-Type: application/json" \
-d '{
"name": "Jane Smith",
"attempts": 3,
"car": "valid-car-id",
"hotel": "invalid-hotel-id",
"flight": "valid-flight-id"
}'
{
"result": {
"message": "Activity task failed",
"status": "failure"
},
"user_id": "jane-smith-935816"
}
To format the documentation, run the following command:
dprint fmt -c dprint.json
To format the Python examples in the documentation, run the following command:
blacken-docs tutorial.md
To format the code, run the following commands:
isort . && black .
If you need further assistance or have any questions, feel free to ask.