Skip to content

KiranHari25121993/temporal-patient-onboarding

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Temporal Demo: new patient onboarding

Shows Temporal workflow execution running on Quarkus. Uses the Temporal Java SDK.

Note

This code is for demo purposes only. It is NOT meant to be used in production.

About

In this demo we show off a patient onboarding workflow. It's main purpose is to:

  • Show how to get up and running with Temporal
  • Show how to easily add retry logic to your workflows using Temporal
  • Show how to easily add compensation logic to your workflows using Temporal
  • Show how you can add resiliency to your applications using Temporal

The demo is composed of three modules:

  1. The onboarding-app module is our app that runs the workflow and its activities. It also includes our onboarding UI.
  2. The onboarding-service module contains our services which the workflow activities are accessing. It is used to show workflow retries and compensation in cases of failures.
  3. The onboarding-model contains our domain model

Running the demo

  1. Start the Temporal Service (docker compose):
 git clone https://github.com/temporalio/docker-compose.git
 cd  docker-compose
 docker-compose up
  1. Clone the repository locally:
git clone https://github.com/tsurdilo/temporal-patient-onboarding.git
cd temporal-patient-onboarding
  1. Build the model:
cd onboarding-model
mvn clean install
  1. Start the demo apps:

Start onboarding-service:

cd onboarding-service
mvn clean install quarkus:dev

Start onboarding-app:

cd onboarding-app
mvn clean install quarkus:dev
  1. Access the demo service Swagger UI via: http://localhost:8090/q/swagger-ui/

  2. Acess the demo app Swagger UI via: http://localhost:8080/q/swagger-ui/

  3. Access the demo UI in browser via: http://localhost:8080

  4. Access the Temporal Web-Ui via: http://localhost:8088

Interacting with the demo

1. Running without failures

Our demo has a simple UI that intially looks like this:

You can type in the new patient information and here are some useful hints:

Our demo workflow activities will associate the zip code you type in with one of the pre-defined hospitals. To get a specific hospital you can use the following zips: 30041, 55902, 90095, 90048, 10065. You can type in any zip you wish but if it's not one of those our workflow activities will associate it with the "default" hospital.

There is a number of conditions which you can use to associate the patient with one of the pre-defined doctors in the demo. These are: Diabetes, Anxiety, Cancer, Asthma. you can type in any condition you wish but if it's not one of theose the workflow activities will associate it with the "default" doctor.

Once you fill in the new patient form click the "Onboard Patient" button.

This will start our workflow run which is associated with the new patient that we are onboarding.

Here is how we can visualize our workflow:

It is basically a pipeline which executes each of our onboarding activities one after the other.

When each activity executes, you will see a notification popup of the activity, for example:

These notifications are pushed from our workflow activities. There is no need to click on the notifications "OK" button. These notifications will automatically close when the assiciated workflow activitiy has completed and will dissapear when the workflow run completes.

After the workflow run completes, the section of bottom of the scren will update to show you that the patient is indeed onboarded:

Now let's take a look at our Temporal Web-UI client, it will show us that our workflow execution has successfully completed:

You can click on the Run Id link and explore the workflow execution history.

2. Simulating Services failure - Retries

For this scenario shut down onboarding-service so it is not running. Start onboarding another patient through the UI and submit the form.

Look at the logs of onboarding-app, you will see that Temporal is retrying the first activity which is failing because of an exception.

After about 5 seconds bring up onboarding-service again and watch the UI. You will see that workflow retries were successfull and you will start seeing the onboarding popup messages and that the patient was successfully onboarded.

3. Simulating Services failure - Compensation

For this scenario shut down onboarding-service so it is not running. Start onboarding another patient through the UI and submit the form.

This time do not bring onboarding-service and wait until our retries finish (we set the max retries to 6 in our workflow). Watch the UI, as after all the retries have been performed you will see a notification popul telling you that the patient was not onboarded.

Now look at the logs of onboarding-app, you will see that right after the defined retries, our workflow has performed its compensation (in this demo it is just printing out a message, but irl it could be doing much much more).

You will see a "no" in the onboarded patients "Onboarded" table column.

4. Simulating Temporal Server Failure - Recovery

For this scenario make sure our app and services are running. Start onboarding another patient through the UI and submit the form. Shortly after, before the workflow completes, shut down the Temporal service.

You will see that the popup messages on the UI will stop maybe after the first or second popup, depending where during the workflow execution you shut down the service.

Now start the Temporal service back up. When it comes back up watch the application UI and the Temporal Web UI. You will see that Temporal has recovered our workflow, has replayed it to the point of failure (where we shut down the Temporal service) and is contuing its execution at that point.

In the Temporal UI you should see that our onboarding workflow is back to the "Running" status and that in our application UI the popup messages resume for the remaining activity executions and that our patient onboarding finishes.

Hope you have fun running this demo! :)

About

Temporal Demo - new patient onboarding

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 73.3%
  • HTML 26.7%