Skip to content

Instantly share code, notes, and snippets.

@maxnorth
Created August 30, 2020 01:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxnorth/a9a860f86425c4890e01f3deb9307b69 to your computer and use it in GitHub Desktop.
Save maxnorth/a9a860f86425c4890e01f3deb9307b69 to your computer and use it in GitHub Desktop.
Durable task emulator bug
using DurableTask.Core;
using System;
using System.Threading.Tasks;
using DurableTask.ServiceBus;
using DurableTask.ServiceBus.Tracking;
using DurableTask.Emulator;
namespace DurableTaskPrototype
{
class Program
{
static async Task Main(string[] args)
{
// get config
//var serviceBusConnectionString = "";
//var storageConnectionString = "";
//var taskHubName = "TaskHubName";
//// get integration objects
//var instanceStore = new AzureTableInstanceStore(taskHubName, storageConnectionString);
//var orchestrationServiceAndClient = new ServiceBusOrchestrationService(serviceBusConnectionString, taskHubName, instanceStore, null, null);
var orchestrationServiceAndClient = new LocalOrchestrationService();
var taskHubClient = new TaskHubClient(orchestrationServiceAndClient); // create orchestrations
var taskHubAgent = new TaskHubWorker(orchestrationServiceAndClient); // start/stop, register services
// initialize
await orchestrationServiceAndClient.CreateIfNotExistsAsync();
// register tasks/orchestrations
taskHubAgent.AddTaskOrchestrations(typeof(StepsOrchestration));
taskHubAgent.AddTaskActivities(new Step1Task(), new Step2Task());
// begin work
var firstInstanceId = Guid.NewGuid().ToString();
var firstInstance = await taskHubClient.CreateOrchestrationInstanceAsync(typeof(StepsOrchestration), firstInstanceId, null);
try
{
await taskHubAgent.StartAsync();
var result = await taskHubClient.WaitForOrchestrationAsync(firstInstance, TimeSpan.FromMinutes(5));
try
{
var secondInstance = await taskHubClient.CreateOrchestrationInstanceAsync(typeof(StepsOrchestration), firstInstanceId, null);
}
catch (Exception ex)
{
Console.Write(ex.Message);
}
await taskHubAgent.StopAsync(true);
}
catch (Exception e)
{
Console.WriteLine($"worker exception: {e}");
}
}
public class StepsOrchestration : TaskOrchestration<string, string>
{
public override async Task<string> RunTask(OrchestrationContext context, string input)
{
string step1Message = await context.ScheduleTask<string>(typeof(Step1Task));
string step2Message = await context.ScheduleTask<string>(typeof(Step2Task), step1Message);
return step2Message;
}
}
public sealed class Step1Task : AsyncTaskActivity<string, string>
{
protected override async Task<string> ExecuteAsync(DurableTask.Core.TaskContext context, string input)
{
return await Task.FromResult("Hello from step 1");
}
}
public sealed class Step2Task : TaskActivity<string, string>
{
protected override string Execute(DurableTask.Core.TaskContext context, string input)
{
return input + "and hello from step 2";
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment