ahydrax / Hangfire.PostgreSql

Alternative PostgreSql Storage Provider for Hangfire
https://www.nuget.org/packages/Hangfire.PostgreSql.ahydrax/
Other
19 stars 7 forks source link

WIP: Closes #8: added NpgsqlTransaction support to Hangfire.PostgreSql #15

Closed schmitch closed 2 years ago

schmitch commented 5 years ago

@ahydrax: this is a PR that would solve Issue #8, it still needs tests, however I already tested it and it looks working.

The design is as follow:

 using (var transaction = await _applicationContext.Database.BeginTransactionAsync(IsolationLevel.RepeatableRead))
            {
                // other sql commands

                var storage = new PostgreSqlStorage(npgsql, "hangfire");
                var client = new RecurringJobManager(storage);

                client.AddOrUpdate($"my-job", JobFromBackup(backupJob), cron);

                transaction.Commit();
            }

it will only work with a NpgsqlTransaction since TransactionScope is only supported within .net standard >= 2.0

ahydrax commented 5 years ago

Hi @schmitch , what if we just upgrade project to netstandard2.0? Anyway we have multitarget project SDKs.

schmitch commented 5 years ago

it's not possible to use netstandard2.0 without dropping support for dotnet core 1.x (See: https://docs.microsoft.com/de-de/dotnet/standard/net-standard)

ahydrax commented 5 years ago

Do we really need to care about .net core 1.x support? Even official support will end soon (see https://dotnet.microsoft.com/platform/support/policy/dotnet-core) The thing I'm worrying now is about full framework support but it's already covered by multitarget build.

schmitch commented 5 years ago

I do not care about .net core 1.x I do not think that many users are on it. and yes full framework is covered by multitarget build.

however even with System.Transactions I would keep the current code and just add System.Transactions aswell, so that everything works. TransactionScope and passing Transactions directly.

schmitch commented 5 years ago

/cc @ahydrax I actually tested the change. and everything works, either via transaction scope or with direct transactions (the latter has benefits)

i.e. the problem with Transaction Scope is that you need to reconfigure PostgreSQL to support prepared transactions