Doh, at least i'm not the only guy who waiting that fix
I recommend you to use the second database for Hangfire server.
Yeah, you are right using separate database for Hangfire most effective solution.
BTW, I recommend that you install Volo.Abp.BackgroundWorkers.HangFire package in the startup project(.MVC, .HttpApi.Host etc..). this way it does not affect the DbMigrator project
Noted.
Cheers
Hi,
I think you should create a database first, hangfire will not create a database for you.
See: https://github.com/HangfireIO/Hangfire/blob/master/src/Hangfire.SqlServer/Install.sql
Hi, Of course we need to create DB first in place. Dbmigrator console application already exists to facilitate this database create operation, right ?
public async Task StartAsync(CancellationToken cancellationToken)
{
using (var application = await AbpApplicationFactory.CreateAsync<hangfireDbMigratorModule>(options =>
{
options.Services.ReplaceConfiguration(_configuration);
options.UseAutofac();
options.Services.AddLogging(c => c.AddSerilog());
}))
{
**await application.InitializeAsync();**
await application
.ServiceProvider
.GetRequiredService<hangfireDbMigrationService>()
.MigrateAsync();
await application.ShutdownAsync();
_hostApplicationLifetime.StopApplication();
}
}
So let me go step by step. Console application is going to initialize modules. Right ?
That means whenever you use Volo.Abp.BackgroundWorkers.HangFire and/or Volo.Abp.BackgroundJobs.HangFire you will also run OnPreApplicationInitialization method. Right ?
public async override Task OnPreApplicationInitializationAsync(ApplicationInitializationContext context)
{
var options = context.ServiceProvider.GetRequiredService<IOptions<AbpBackgroundWorkerOptions>>().Value;
if (!options.IsEnabled)
{
var hangfireOptions = context.ServiceProvider.GetRequiredService<IOptions<AbpHangfireOptions>>().Value;
hangfireOptions.BackgroundJobServerFactory = CreateOnlyEnqueueJobServer;
}
await context.ServiceProvider
.GetRequiredService<IBackgroundWorkerManager>()
.StartAsync();
}
public override void OnPreApplicationInitialization(ApplicationInitializationContext context)
{
AsyncHelper.RunSync(() => OnPreApplicationInitializationAsync(context));
}
More or less whenever you start BackgroundWorkerManager you will also going to try to create **BackgroundJobServer **
await context.ServiceProvider
.GetRequiredService<IBackgroundWorkerManager>()
.StartAsync();
And **BackgroundJobServer **ceration requires JobStorage .Btw BackgroundJobServer constructor used in the abp package is the obsolete one
private BackgroundJobServer CreateJobServer(IServiceProvider serviceProvider)
{
Storage = Storage ?? serviceProvider.GetRequiredService<JobStorage>();
ServerOptions = ServerOptions ?? serviceProvider.GetService<BackgroundJobServerOptions>() ?? new BackgroundJobServerOptions();
AdditionalProcesses = AdditionalProcesses ?? serviceProvider.GetServices<IBackgroundProcess>();
return new BackgroundJobServer(ServerOptions, Storage, AdditionalProcesses,
ServerOptions.FilterProvider ?? serviceProvider.GetRequiredService<IJobFilterProvider>(),
ServerOptions.Activator ?? serviceProvider.GetRequiredService<JobActivator>(),
serviceProvider.GetService<IBackgroundJobFactory>(),
serviceProvider.GetService<IBackgroundJobPerformer>(),
serviceProvider.GetService<IBackgroundJobStateChanger>()
);
}
If you don't define any JobStorage that will cause exception about JobStorage can't be null exception
GlobalConfiguration.Configuration
.UseSqlServerStorage(configuration.GetConnectionString("Default"));
If you define JobStorage then it will going to execute https://github.com/HangfireIO/Hangfire/blob/master/src/Hangfire.SqlServer/Install.sql scripts.
And as you already aware of that, scripts requires database in first place.
And if you remember we are about create DB :)
Long of short: Your Volo.Abp.BackgroundWorkers.HangFire and/or Volo.Abp.BackgroundJobs.HangFire are killing DbMigrator functionality by their nature of design.
Steps to reproduce the issue :
1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource
1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource1 retry, DbConnectionOptions userOptions) at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource
1 retry, DbConnectionOptions userOptions)
at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource1 retry) at System.Data.SqlClient.SqlConnection.Open() at Hangfire.SqlServer.SqlServerStorage.CreateAndOpenConnection() at Hangfire.SqlServer.SqlServerStorage.UseConnection[T](DbConnection dedicatedConnection, Func
2 func)
at Hangfire.SqlServer.SqlServerStorage.Initialize()
ClientConnectionId:818770b2-7b19-493b-974a-ffce2693698f
Error Number:4060,State:1,Class:11 GlobalConfiguration.Configuration
// Use custom connection string
.UseSqlServerStorage(configuration.GetConnectionString("Default"));
public override void ConfigureServices(ServiceConfigurationContext context)
{
var configuration = context.Services.GetConfiguration();
Configure<AbpBackgroundJobOptions>(options =>
{
options.IsJobExecutionEnabled = false;
});
Configure<AbpBackgroundWorkerOptions>(options =>
{
options.IsEnabled = false;
});
}
AbpBackgroundWorkersHangfireModule on pre application initilization stage :
public async override Task OnPreApplicationInitializationAsync(ApplicationInitializationContext context)
{
var options = context.ServiceProvider.GetRequiredService<IOptions<AbpBackgroundWorkerOptions>>().Value;
if (!options.IsEnabled)
{
var hangfireOptions = context.ServiceProvider.GetRequiredService<IOptions<AbpHangfireOptions>>().Value;
hangfireOptions.BackgroundJobServerFactory = CreateOnlyEnqueueJobServer;
}
await context.ServiceProvider
.GetRequiredService<IBackgroundWorkerManager>()
.StartAsync();
}
maybe there missing module definition at during code generation.
Ok, thx for the fix and update, i will look forward 5.0 release
Check the vstest platform architecture: https://github.com/microsoft/vstest-docs/blob/main/RFCs/0001-Test-Platform-Architecture.md Check the vstest data collectors: https://github.com/microsoft/vstest-docs/blob/main/RFCs/0006-DataCollection-Protocol.md Check the .runtimesettings : https://docs.microsoft.com/en-us/visualstudio/test/configure-unit-tests-by-using-a-dot-runsettings-file?branch=release-16.4&view=vs-2019
my unit tests are not running when i use commercial volo packages in my module project i believe that is due to their license check
to collect for information regarding error i tried attached data collector to my testhost
datacollector log indicates :
TpTrace Information: 0 : 29556, 1, 2021/11/29, 10:18:52.689, 5623983708510, datacollector.exe, Listening on Endpoint : 127.0.0.1:58503
TpTrace Information: 0 : 29556, 1, 2021/11/29, 10:18:52.709, 5623983903030, datacollector.exe, DataCollectionRequestHandler.ProcessRequests : DataCollection started.
TpTrace Information: 0 : 29556, 1, 2021/11/29, 10:18:52.752, 5623984339050, datacollector.exe, DataCollectionRequestHandler.ProcessRequests : Datacollector received message: (DataCollection.TestHostLaunched) -> {
"ProcessId": 22052
}
TpTrace Information: 0 : 29556, 1, 2021/11/29, 10:18:52.778, 5623984599936, datacollector.exe, ProcessDumpUtility.CrashDump: Creating mini dump of process testhost.x86 (22052) into temporary path 'C:\Users\xxxxxxx\AppData\Local\Temp\c0e3fc35-5300-4319-a040-548012a5c65a'.
TpTrace Information: 0 : 29556, 1, 2021/11/29, 10:18:52.780, 5623984616998, datacollector.exe, CrashDumperFactory: Creating dumper for Microsoft Windows 10.0.19042 with target framework .NETCoreApp,Version=v5.0.
TpTrace Information: 0 : 29556, 1, 2021/11/29, 10:18:52.780, 5623984618606, datacollector.exe, CrashDumperFactory: This is Windows on .NETCoreApp,Version=v5.0, returning the .NETClient dumper which uses env variables to collect crashdumps of testhost and any child process.
TpTrace Information: 0 : 29556, 4, 2021/11/29, 10:18:53.106, 5623987877765, datacollector.exe, Using the buffer size of 16384 bytes
TpTrace Information: 0 : 29556, 4, 2021/11/29, 10:18:53.106, 5623987878866, datacollector.exe, Accepted Client request and set the flag
TpTrace Information: 0 : 29556, 7, 2021/11/29, 10:19:06.855, 5624125359620, datacollector.exe, DataCollectionTestCaseEventHandler: Test case starting.
TpTrace Information: 0 : 29556, 7, 2021/11/29, 10:19:06.900, 5624125815083, datacollector.exe, Blame Collector : Test Case Start
TpTrace Information: 0 : 29556, 7, 2021/11/29, 10:19:06.902, 5624125830635, datacollector.exe, DataCollectionTestCaseEventHandler: Test case 'Siemens.Odms.Samples.SampleAppService_Tests.GetAsync - 59f413e1-9026-3a67-eb02-b7f70f6b998a' started.
TpTrace Error: 0 : 29556, 7, 2021/11/29, 10:19:08.834, 5624145153965, datacollector.exe, DataCollectionRequestHandler.HandleBeforeTestRunStart : Error occurred during initialization of TestHost : System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
--- End of inner exception stack trace ---
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.IO.Stream.ReadByte()
at System.IO.BinaryReader.ReadByte()
at System.IO.BinaryReader.Read7BitEncodedInt()
at System.IO.BinaryReader.ReadString()
at Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.SocketCommunicationManager.ReceiveRawMessage()
at Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.SocketCommunicationManager.ReceiveMessage()
at Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.DataCollection.DataCollectionTestCaseEventHandler.ProcessRequests()
at Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.DataCollection.DataCollectionRequestHandler.<HandleBeforeTestRunStart>b__24_0()
TpTrace Information: 0 : 29556, 1, 2021/11/29, 10:19:08.868, 5624145489916, datacollector.exe, DataCollectionRequestHandler.ProcessRequests : Datacollector received message: (DataCollection.AfterTestRunEnd) -> false
My current abp license allows me to access the commercial module source code. So i just disabled license checker at app init stage
Now i can run my unit test after this modification
Can you share an example project that shows how unit tests should be if we use a commercial package within the module? br
Could you wait for a few seconds when you click the PreRelease checkbox and see if it makes any difference ?
Nope, at least for me
It may also not related with marking package with "preview". Nuget server endpoint delivers un expected results Or Package marking is wrong and endpoint delivering miss information
Is there any possibility to get try count in the job code ?
Can you explain why do you want to do this?
According to following explanation https://docs.abp.io/en/abp/4.3/Background-Jobs#exception-handling Background job is automatically re-tried after certain period of time. However i would like to control it with re-try count.
In a very simple way: