Open Closed

ABP IO Background job is not getting triggered. #605


User avatar
0
suraj.kumbhar created
  • ABP Commercial version: v3.2.1
  • UI type: Razor
  • Tiered (MVC) or Identity Server Seperated (Angular): no
  • Exception message and stack trace:
  • Steps to reproduce the issue: Database : MongoDB

We have followed this document link https://docs.abp.io/en/abp/latest/Background-Jobs to crate a job and implemented exactly like this but somehow that job is not getting triggered and as soon as entry get added in Background Table IsAbandoned flag set to true. Sometimes we also observed this behaviour is that it suddendly start executing job and again stopped working. Cean -> rebuild- > build project is working some times. its a weird things we are obeserving. Here is the sample code,

public enum ImportTableName
{
    Test1 = 1,
    Test2 = 2
}

[BackgroundJobName("ImportJob")]
public class BackgroundImportJobArgs
{
	public string FilePath { get; set; }
	public ImportTableName ImportTableName { get; set; }
}

public class BackgroundImportJob : AsyncBackgroundJob<BackgroundImportJobArgs>, ITransientDependency
{
	private readonly IImportTblAppService importTbl;

	public BackgroundImportJob(IImportTblAppService importTbl)
	{
		this.importTbl = importTbl;
	}

	public override async Task ExecuteAsync(BackgroundImportJobArgs args)
	{
		switch (args.ImportTableName)
		{
			case ImportTableName.Test1:
				await importTbl.AddTest1(args.FilePath, args.ImportTableName);
				System.IO.File.Delete(args.FilePath);
				break;
			default:
				break;
		}
	}
}
    
public class ImportTblAppService : DemoAppService, IImportTblAppService
{
	private readonly ITest1Repository _test1Repository;
	private readonly IBackgroundJobManager _backgroundJobManager;
	public ImportTblAppService(ITest1Repository test1Repository, IBackgroundJobManager backgroundJobManager)
	{
		_test1Repository = test1Repository;
		_backgroundJobManager = backgroundJobManager;
	}

	public async Task AddTest1(string filePath, ImportTableName tablename)
	{
		/* Here contains Insert Logic */
	} 

	public async Task ScheduleImportJob(string filePath, ImportTableName tablename)
	{
		await _backgroundJobManager.EnqueueAsync(new BackgroundImportJobArgs { FilePath = filePath, ImportTableName = tablename }).ConfigureAwait(false);
	}
}

12 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Can you share some code to reproduce the problem?

  • User Avatar
    0
    suraj.kumbhar created

    Sample code Added.

  • User Avatar
    0
    suraj.kumbhar created

    @maliming Could you please revert urgently on above ? We are pressed for time for importing client data and this Background job working is very crucial .

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi @suraj.kumbhar

    I'm checking.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    When IsAbandoned is true, it means that an exception has occurred.

    Can you check the logs of your application?

  • User Avatar
    0
    suraj.kumbhar created

    Hi @maliming, Nothing gets logged, dont know why, The job that was working multiple times and suddenly it stopped without making any changes in code. Is job getting triggered at your end? if yes please provide us that working sample.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    You can check your application logs, log file is in the logs folder of your website root directory

  • User Avatar
    0
    suraj.kumbhar created

    I know i checked, nothing gets logged and brekpoint also gets move to step after EnqueAsync();

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi @suraj.kumbhar

    Can you share your project to me? include the necessary steps.

    I will try to reproduce your problem.

    My email: liming.ma@volosoft.com

    Thanks.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    This is my test application service.

    It works, but there will be a few exceptions. My local mongodb will not get an exception. I think it may be caused by your mongodb.

    /* Inherit your application services from this class.
     */
    public abstract class MyAppAppService : ApplicationService
    {
    	protected MyAppAppService()
    	{
    		LocalizationResource = typeof(MyAppResource);
    	}
    }
    
    
    public enum ImportTableName
    {
    	Test1 = 1,
    	Test2 = 2
    }
    
    [BackgroundJobName("ImportJob")]
    public class BackgroundImportJobArgs
    {
    	public string FilePath { get; set; }
    	public ImportTableName ImportTableName { get; set; }
    }
    
    public interface IImportTblAppService : IApplicationService
    {
    	Task AddTest1(string filePath, ImportTableName tablename);
    }
    
    public class BackgroundImportJob : AsyncBackgroundJob<BackgroundImportJobArgs>, ITransientDependency
    {
    	private readonly IImportTblAppService importTbl;
    
    	public BackgroundImportJob(IImportTblAppService importTbl)
    	{
    		this.importTbl = importTbl;
    	}
    
    	public override async Task ExecuteAsync(BackgroundImportJobArgs args)
    	{
    		Console.WriteLine("ExecuteAsync");
    
    		await importTbl.AddTest1(args.FilePath, args.ImportTableName);
    	}
    }
    
    public class ImportTblAppService : MyAppAppService, IImportTblAppService
    {
    	private readonly IBackgroundJobManager _backgroundJobManager;
    	public ImportTblAppService(IBackgroundJobManager backgroundJobManager)
    	{
    		_backgroundJobManager = backgroundJobManager;
    	}
    
    	public Task AddTest1(string filePath, ImportTableName tablename)
    	{
    		Console.WriteLine("AddTest1");
    
    		return Task.CompletedTask;
    	}
    
    	public async Task ScheduleImportJob(string filePath, ImportTableName tablename)
    	{
    		await _backgroundJobManager.EnqueueAsync(new BackgroundImportJobArgs { FilePath = filePath, ImportTableName = tablename });
    	}
    }
    
    [20:10:03 ERR] An exception occurred while receiving a message from the server.
    MongoDB.Driver.MongoConnectionException: An exception occurred while receiving a message from the server.
     ---> System.IO.IOException: Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a period of tim
    e, or established connection failed because connected host has failed to respond..
     ---> System.Net.Sockets.SocketException (10060): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection f
    ailed because connected host has failed to respond.
       --- End of inner exception stack trace ---
       at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
       at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.GetResult(Int16 token)
       at System.Net.Security.SslStream.<FillBufferAsync>g__InternalFillBufferAsync|215_0[TReadAdapter](TReadAdapter adap, ValueTask`1 task, Int32 min, Int32 initial)
       at System.Net.Security.SslStream.ReadAsyncInternal[TReadAdapter](TReadAdapter adapter, Memory`1 buffer)
       at MongoDB.Driver.Core.Misc.StreamExtensionMethods.ReadAsync(Stream stream, Byte[] buffer, Int32 offset, Int32 count, TimeSpan timeout, CancellationToken cancellationToken)
       at MongoDB.Driver.Core.Misc.StreamExtensionMethods.ReadBytesAsync(Stream stream, Byte[] buffer, Int32 offset, Int32 count, TimeSpan timeout, CancellationToken cancellationToken)
       at MongoDB.Driver.Core.Connections.BinaryConnection.ReceiveBufferAsync(CancellationToken cancellationToken)
       --- End of inner exception stack trace ---
       at MongoDB.Driver.Core.Connections.BinaryConnection.ReceiveMessageAsync(Int32 responseTo, IMessageEncoderSelector encoderSelector, MessageEncoderSettings messageEncoderSettings, C
    ancellationToken cancellationToken)
       at MongoDB.Driver.Core.WireProtocol.CommandUsingQueryMessageWireProtocol`1.ExecuteAsync(IConnection connection, CancellationToken cancellationToken)
       at MongoDB.Driver.Core.Servers.Server.ServerChannel.ExecuteProtocolAsync[TResult](IWireProtocol`1 protocol, ICoreSession session, CancellationToken cancellationToken)
       at MongoDB.Driver.Core.Operations.RetryableWriteOperationExecutor.ExecuteAsync[TResult](IRetryableWriteOperation`1 operation, RetryableWriteContext context, CancellationToken canc
    ellationToken)
       at MongoDB.Driver.Core.Operations.BulkUnmixedWriteOperationBase`1.ExecuteBatchAsync(RetryableWriteContext context, Batch batch, CancellationToken cancellationToken)
       at MongoDB.Driver.Core.Operations.BulkUnmixedWriteOperationBase`1.ExecuteBatchesAsync(RetryableWriteContext context, CancellationToken cancellationToken)
       at MongoDB.Driver.Core.Operations.BulkMixedWriteOperation.ExecuteBatchAsync(RetryableWriteContext context, Batch batch, CancellationToken cancellationToken)
       at MongoDB.Driver.Core.Operations.BulkMixedWriteOperation.ExecuteAsync(IWriteBinding binding, CancellationToken cancellationToken)
       at MongoDB.Driver.OperationExecutor.ExecuteWriteOperationAsync[TResult](IWriteBinding binding, IWriteOperation`1 operation, CancellationToken cancellationToken)
       at MongoDB.Driver.MongoCollectionImpl`1.ExecuteWriteOperationAsync[TResult](IClientSessionHandle session, IWriteOperation`1 operation, CancellationToken cancellationToken)
       at MongoDB.Driver.MongoCollectionImpl`1.BulkWriteAsync(IClientSessionHandle session, IEnumerable`1 requests, BulkWriteOptions options, CancellationToken cancellationToken)
       at MongoDB.Driver.MongoCollectionImpl`1.UsingImplicitSessionAsync[TResult](Func`2 funcAsync, CancellationToken cancellationToken)
       at MongoDB.Driver.MongoCollectionBase`1.InsertOneAsync(TDocument document, InsertOneOptions options, Func`3 bulkWriteAsync)
       at Volo.Abp.Domain.Repositories.MongoDB.MongoDbRepository`2.InsertAsync(TEntity entity, Boolean autoSave, CancellationToken cancellationToken)
       at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo)
       at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapterWithReturnValue`1.ProceedAsync()
       at Volo.Abp.Uow.UnitOfWorkInterceptor.InterceptAsync(IAbpMethodInvocation invocation)
       at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter`1.InterceptAsync[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo, Func`3 proceed)
       at Volo.Abp.BackgroundJobs.BackgroundJobStore.InsertAsync(BackgroundJobInfo jobInfo)
       at Volo.Abp.BackgroundJobs.DefaultBackgroundJobManager.EnqueueAsync(String jobName, Object args, BackgroundJobPriority priority, Nullable`1 delay)
       at Volo.Abp.BackgroundJobs.DefaultBackgroundJobManager.EnqueueAsync[TArgs](TArgs args, BackgroundJobPriority priority, Nullable`1 delay)
       at MyApp.ImportTblAppService.ScheduleImportJob(String filePath, ImportTableName tablename) in C:\Users\maliming\Desktop\New folder (2)\src\MyApp.Application\MyAppAppService.cs:lin
    e 75
       at lambda_method(Closure , Object )
       at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, O
    bject[] arguments)
       at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)
       at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.&lt;InvokeNextActionFilterAsync&gt;g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope s
    cope, Object state, Boolean isCompleted)
       at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
       at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
       at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.&lt;InvokeInnerFilterAsync&gt;g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope,
     Object state, Boolean isCompleted)
       at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.&lt;InvokeNextExceptionFilterAsync&gt;g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object
    state, Boolean isCompleted)
    
    

  • User Avatar
    0
    suraj.kumbhar created

    I think this issue is only because of MongoDB, we are suing Azure CosmosDB with Mongo API Version 3.6 also. It has already issue present from last 2 months https://support.abp.io/QA/Questions/473/MongoDBDriverMongoCommandException-Command-aggregate-failed-Error2-After-deployment-on-Azure-using-CosmosDB.

    Due to above issue we have choose to use 3.2 version for mongo in Cosmos and we started working. But when we want to implement Backgroung job its not working.

    We have to use MongoDb only. Please suggest a workaround above issues. It has performance issue, Aggregation Issues, Background job is not getting triggered.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Because you don't always get this exception, maybe you can use try-catch to retry.

Made with ❤️ on ABP v9.1.0-preview. Updated on December 13, 2024, 06:09