أنشطة "raif"

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. Create new application by using application template
  2. Add Hangfire.SqlServer package for job persistence
  3. Add Volo.Abp.HangFire (this should enough to force convert existing background jobs into the hangfire one like tokencleanup etc)
  4. Define connection string for job storage
  5. Run Db Migrator

  • ABP Framework version: v5.2.0
  • UI type: Blazor
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): yes
  • Exception message and stack trace: [11:19:59 INF] Start installing Hangfire SQL objects... [11:20:11 WRN] An exception occurred while trying to perform the migration. Retrying... System.Data.SqlClient.SqlException (0x80131904): Cannot open database "hangfiretest" requested by the login. The login failed. Login failed for user 'AD001\z003dr8m'. at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, Boolean applyTransientFaultHandling) at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource1 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, TaskCompletionSource1 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, Func2 func) at Hangfire.SqlServer.SqlServerStorage.Initialize() ClientConnectionId:818770b2-7b19-493b-974a-ffce2693698f Error Number:4060,State:1,Class:11
  • Steps to reproduce the issue:"
  1. Create new application by using application template
  2. Add Hangfire.SqlServer package for job storage persistence
  3. Add Volo.Abp.HangFire for AbpHangfireOptions
  4. Define connection string for job storage e.g :
	GlobalConfiguration.Configuration
		// Use custom connection string
		.UseSqlServerStorage(configuration.GetConnectionString("Default"));
  1. Even if you try to disable it by using AbpBackgroundJobOptions and AbpBackgroundWorkerOptions options, AbpBackgroundWorkersHangfireModule and AbpBackgroundJobsHangfireModule will try to create Job Server (CreateOnlyEnqueueJobServer)
	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&lt;IOptions&lt;AbpBackgroundWorkerOptions&gt;>().Value;
    if (!options.IsEnabled)
    {
        var hangfireOptions = context.ServiceProvider.GetRequiredService&lt;IOptions&lt;AbpHangfireOptions&gt;>().Value;
        hangfireOptions.BackgroundJobServerFactory = CreateOnlyEnqueueJobServer;
    }
    
    await context.ServiceProvider
        .GetRequiredService&lt;IBackgroundWorkerManager&gt;()
        .StartAsync(); 
}
  1. GG. As you can imagine, at that stage DB is not created and Hangfire SQL intsall scripts are going to fail.
  • ABP Framework version: v5.1.1
  • UI type: MVC
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): yes
  • Steps to reproduce:
  • Create new module project by using module template with ui
  • Perform db updates
  • Launch IdentityServer, ApiHost and WebHost
  • Use menu item of "Settings"

maybe there missing module definition at during code generation.

Ok, thx for the fix and update, i will look forward 5.0 release

/bump

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

  • ABP Framework version: v4.4.4
  • UI type: MVC
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): yes
  • Exception message and stack trace: 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()
  • Steps to reproduce the issue:"
  1. create new project by using abp suite module template
  2. add commercial package to the domain layer (e.g. filemanagement)
  3. create a new unit test (no extra step taken after code generation)
  4. try to debug/run test

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:

  • Enqueue job after certain act (e.g. entity creation, any certain logic)
  • Try do some operation
  • If you get exception re-try again
  • If everything went well set "some value" to the "A"
  • If you tried X times and if you still get exception then set "some value" to the "B"
عرض 21 الي 30 من 54 إدخالات
Made with ❤️ on ABP v8.2.0-preview Updated on مارس 25, 2024, 15:11