2020-07-14 13:24:07 +00:00
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
|
using NodaTime;
|
|
|
|
|
using System.Threading.Tasks;
|
2020-10-18 08:40:31 +00:00
|
|
|
using YesSql.Provider.Sqlite;
|
2020-07-14 13:24:07 +00:00
|
|
|
|
|
|
|
|
namespace Elsa.Samples.DistributedLock
|
|
|
|
|
{
|
2020-10-18 08:40:31 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Demonstrates the use of a distributed locking provider.
|
|
|
|
|
/// Make sure that you have a Redis host installed or use the docker-compose.yaml file to run it on Docker.
|
|
|
|
|
/// </summary>
|
2020-07-14 13:24:07 +00:00
|
|
|
internal static class Program
|
|
|
|
|
{
|
2020-10-18 08:40:31 +00:00
|
|
|
private static async Task Main() => await CreateHostBuilder().UseConsoleLifetime().Build().RunAsync();
|
2020-07-14 13:24:07 +00:00
|
|
|
|
|
|
|
|
public static IHostBuilder CreateHostBuilder() =>
|
|
|
|
|
Host.CreateDefaultBuilder()
|
2020-10-18 08:40:31 +00:00
|
|
|
.ConfigureServices(
|
|
|
|
|
(hostContext, services) =>
|
|
|
|
|
{
|
|
|
|
|
services
|
|
|
|
|
.AddElsa(options => options
|
2020-10-18 10:27:40 +00:00
|
|
|
.UsePersistence(db => db.UseSqLite("Data Source=elsa.db;Cache=Shared"))
|
2020-10-18 08:40:31 +00:00
|
|
|
.UseRedisLockProvider("localhost:6379,abortConnect=false"))
|
|
|
|
|
.AddConsoleActivities()
|
2020-10-27 11:32:53 +00:00
|
|
|
.AddTimerActivities(timer => timer.SweepInterval = Duration.FromSeconds(5))
|
2020-10-18 08:40:31 +00:00
|
|
|
.AddWorkflow<RecurringWorkflow>();
|
|
|
|
|
});
|
2020-07-14 13:24:07 +00:00
|
|
|
}
|
|
|
|
|
}
|