-
-
Save dcomartin/6aeab09df08f5b476bfe47612d822d1e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Workflow] | |
public class MyWorkflow | |
{ | |
[WorkflowRun] | |
public async Task<MyActivities.Order> RunAsync() | |
{ | |
var order = new MyActivities.Order(Guid.NewGuid()); | |
await Workflow.ExecuteActivityAsync<MyActivities>(activities => activities.PlaceOrder(order), new ActivityOptions() { | |
StartToCloseTimeout = TimeSpan.FromMinutes(5), | |
}); | |
var transactionId = await Workflow.ExecuteActivityAsync<MyActivities, Guid>(activities => activities.ProcessPayment(order, new MyActivities.CreditCard()), new ActivityOptions { | |
StartToCloseTimeout = TimeSpan.FromMinutes(5), | |
}); | |
Console.WriteLine($"Transaction Id: {transactionId} for Order Id {order.OrderId}"); | |
await Workflow.ExecuteActivityAsync<MyActivities>(activities => activities.EmailConfirmation(order), new ActivityOptions { | |
StartToCloseTimeout = TimeSpan.FromMinutes(5), | |
}); | |
Console.WriteLine("Workflow Complete"); | |
return order; | |
} | |
} | |
public class MyActivities | |
{ | |
[Activity] | |
public Task PlaceOrder(Order order) | |
{ | |
Console.WriteLine($"Place Order Id {order.OrderId}"); | |
return Task.CompletedTask; | |
} | |
[Activity] | |
public async Task<Guid> ProcessPayment(Order order, CreditCard creditCard) | |
{ | |
Console.WriteLine($"Process Payment for Order Id {order.OrderId}"); | |
await Task.Delay(TimeSpan.FromSeconds(5)); | |
return Guid.NewGuid(); | |
} | |
[Activity] | |
public Task EmailConfirmation(Order order) | |
{ | |
Console.WriteLine($"Email Confirmation for Order Id {order.OrderId}"); | |
return Task.CompletedTask; | |
} | |
public record Order(Guid OrderId); | |
public record CreditCard(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment