You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe the problem.
I am trying to get the queuing of a job to be set in the same transaction as the request.
Describe the solution you'd like
I see that Quartz already supports this but there is no easy way to configure it in ABP. I came out with a solution but wanted to ask if you see any issues with it or a better way to do it.
As Quartz has it, this class has to handle connections for storing and running jobs.
public class DBContextJobStoreCMT : JobStoreCMT
{
private readonly IUnitOfWorkManager _unitOfWorkManager;
public DBContextJobStoreCMT(IUnitOfWorkManager unitOfWorkManager)
{
_unitOfWorkManager = unitOfWorkManager;
OpenConnection = true;
}
protected override ConnectionAndTransactionHolder GetNonManagedTXConnection()
{
IUnitOfWork uow = _unitOfWorkManager.Current;
if (uow != null)
{
IReadOnlyList<IDatabaseApi> databaseapis = ((UnitOfWork)uow).GetAllActiveDatabaseApis();
if (databaseapis.Count == 1)
{
var DatabaseAux = databaseapis.FirstOrDefault();
if (DatabaseAux is EfCoreDatabaseApi)
{
var dbConnectionAux = ((EfCoreDatabaseApi)DatabaseAux).DbContext.Database.GetDbConnection();
if (dbConnectionAux.State != System.Data.ConnectionState.Open)
{
dbConnectionAux.OpenAsync().Wait();
}
var transactionAux = ((EfCoreDatabaseApi)DatabaseAux).DbContext.Database.CurrentTransaction?.GetDbTransaction();
return new UOWConnectionAndTransactionHolder(dbConnectionAux, transactionAux);
}
}
}
return base.GetNonManagedTXConnection();
}
protected override void CloseConnection(ConnectionAndTransactionHolder connectionAndTransactionHolder)
{
if (!(connectionAndTransactionHolder is UOWConnectionAndTransactionHolder))
{
connectionAndTransactionHolder.Connection.Close();
}
}
}
public class UOWConnectionAndTransactionHolder : ConnectionAndTransactionHolder
{
public UOWConnectionAndTransactionHolder(DbConnection connection, DbTransaction transaction) : base(connection, transaction)
{
}
}
}
Additional context
No response
The text was updated successfully, but these errors were encountered:
Is there an existing issue for this?
Is your feature request related to a problem? Please describe the problem.
I am trying to get the queuing of a job to be set in the same transaction as the request.
Describe the solution you'd like
I see that Quartz already supports this but there is no easy way to configure it in ABP. I came out with a solution but wanted to ask if you see any issues with it or a better way to do it.
As Quartz has it, this class has to handle connections for storing and running jobs.
}
Additional context
No response
The text was updated successfully, but these errors were encountered: