Wrap SQL Server EF Core workflow commits in a provider-safe transaction and buffer commit notifications until persistence succeeds. Also preserve dirty activity context state until commit success and make bookmark queue retries resilient to processed-row deletion and transient distributed lock misses. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
59 lines
2.7 KiB
C#
59 lines
2.7 KiB
C#
using System.Reflection;
|
|
using Elsa.Persistence.EFCore.Modules.Runtime;
|
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
|
|
|
// ReSharper disable once CheckNamespace
|
|
namespace Elsa.Persistence.EFCore.Extensions;
|
|
|
|
/// <summary>
|
|
/// Provides extensions to configure EF Core to use SQL Server.
|
|
/// </summary>
|
|
public static class SqlServerProvidersExtensions
|
|
{
|
|
private static Assembly Assembly => typeof(SqlServerProvidersExtensions).Assembly;
|
|
|
|
public static TFeature UseSqlServer<TFeature, TDbContext>(this PersistenceFeatureBase<TFeature, TDbContext> feature,
|
|
string connectionString,
|
|
ElsaDbContextOptions? options = null,
|
|
Action<SqlServerDbContextOptionsBuilder>? configure = null)
|
|
where TDbContext : ElsaDbContextBase
|
|
where TFeature : PersistenceFeatureBase<TFeature, TDbContext>
|
|
{
|
|
return feature.UseSqlServer(Assembly, connectionString, options, configure);
|
|
}
|
|
|
|
public static TFeature UseSqlServer<TFeature, TDbContext>(this PersistenceFeatureBase<TFeature, TDbContext> feature,
|
|
Func<IServiceProvider, string> connectionStringFunc,
|
|
ElsaDbContextOptions? options = null,
|
|
Action<SqlServerDbContextOptionsBuilder>? configure = null)
|
|
where TDbContext : ElsaDbContextBase
|
|
where TFeature : PersistenceFeatureBase<TFeature, TDbContext>
|
|
{
|
|
return feature.UseSqlServer(Assembly, connectionStringFunc, options, configure);
|
|
}
|
|
|
|
public static TFeature UseSqlServer<TFeature, TDbContext>(this PersistenceFeatureBase<TFeature, TDbContext> feature,
|
|
Assembly migrationsAssembly,
|
|
string connectionString,
|
|
ElsaDbContextOptions? options = null,
|
|
Action<SqlServerDbContextOptionsBuilder>? configure = null)
|
|
where TDbContext : ElsaDbContextBase
|
|
where TFeature : PersistenceFeatureBase<TFeature, TDbContext>
|
|
{
|
|
return feature.UseSqlServer(migrationsAssembly, _ => connectionString, options, configure);
|
|
}
|
|
|
|
public static TFeature UseSqlServer<TFeature, TDbContext>(this PersistenceFeatureBase<TFeature, TDbContext> feature,
|
|
Assembly migrationsAssembly,
|
|
Func<IServiceProvider, string> connectionStringFunc,
|
|
ElsaDbContextOptions? options = null,
|
|
Action<SqlServerDbContextOptionsBuilder>? configure = null)
|
|
where TDbContext : ElsaDbContextBase
|
|
where TFeature : PersistenceFeatureBase<TFeature, TDbContext>
|
|
{
|
|
feature.DbContextOptionsBuilder = (sp, db) => db.UseElsaSqlServer(migrationsAssembly, connectionStringFunc(sp), options, configure);
|
|
if (feature is EFCoreWorkflowRuntimePersistenceFeature runtimePersistenceFeature)
|
|
runtimePersistenceFeature.UseWorkflowCommitTransaction = true;
|
|
return (TFeature)feature;
|
|
}
|
|
} |