Skip to content

kaushiksk/durabletask-samples

Repository files navigation

durabletask-samples

Code samples to better understand the execution of orchestrations authored using https://github.com/Azure/durabletask/

Pre-requisites

You will need a Azure Storage connection string. By default the app will use the local development server of Azure Storage Simulator, ensure that it is up and running.
You can also use an actual Azure Storage instance in the cloud, update the AzureStorageConnectionString config in App.config in that case.

Running the samples

It is recommended to run the samples from a commandline, ideally in split terminals to see the logs from the client and worker side-by-side.
If you're running the samples from the command line, navigate to the root folder with the sln, and run dotnet build.

In Terminal 1, start the client:

> cd DurableTaskClient
> dotnet run

The DurableTaskClient window will display a list of samples to choose from

In Terminal 2, start the worker:

> cd DurableTaskWorker
> dotnet run

DurableTaskWorkerwindow will print the execution logs.

Once you choose a sample from the client, you will see the execution logs in the worker terminal.

The program will also launch a new window where you can manage the instance and perform actions like Pause and Resume on the orchestration instance.

If you're running the samples from Visual Studio, make sure that you set DurableTaskClient, DurableTaskWorker and DurableTaskManager as startup projects. To do this, in the Solution Explorer of VS, Right-Click on the solution > Properties > Startup Projects > Multiple Startup Projects.
Also ensure LaunchInstanceManager is set to false is App.config as the path to this is hardcoded assuming that DurableTaskClient is run from a terminal. You can then run the samples by pressing F5.

Simulating Disaster Scenarios

To simulate a disaster scenario for the worker, and understand the execution flow when a worker recovers, it is recommended to run the DurableTaskClient and DurableTaskWorker from two separate terminals.
You can set DisableOrchestrationVerboseLogs to true and LogDtfCoreEventTraces to false in App.config for this scenario.

Note: Running dotnet run disableVerboseLogs has the same effect as setting DisableOrchestrationVerboseLogs to true

Start the DurableTaskClient and DurableTaskWorker in two separate terminals as shown above. You can select from one of the longer running orchestrations like InlineForLoopTestingOrchestration, FixedPollingWithInlineRetriesOrchestration or UnboundedPollingWithInlineRetriesOrchestration.


Execution will begin in the worker after a few seconds, and you will start seeing logs from your selected orchestration and it's child activities. Mid-way between the execution, for example, when InlineForLoopTestingOrchestration is executing for i = 2, you can kill the worker process in Terminal 2 by issuing a Ctrl-C.

Now bring back the worker again by executing dotnet run in the DurableTaskWorker folder again like before.

You will notice that the worker will resume where it left off. In the case of InlineForLoopTestingOrchestration, if you killed the process when it was executing i = 2, the execution would resume from i = 2!

Dig Deeper

To understand the execution flow better, start by setting the DisableOrchestrationVerboseLogs flag in App.config to false before running the worker. This is the default configuration as well. This will give you clear idea of the orchestation code execution from beginning to end.

Once this is clear, set LogDtfCoreEventTraces to true. This will capture all events from the DTF Core library and display the various orchestration control events from the framework.

Note: After every change to App.Config, please make sure you build the sln again by running dotnet build from the root folder.

About

Samples to better understand the execution of orchestrations authored using https://github.com/Azure/durabletask/

Topics

Resources

Stars

Watchers

Forks

Languages