- ABP Framework version: v4.3.1
- UI type: Angular
- DB provider: EF Core
- Tiered (MVC) or Identity Server Separated (Angular): no / yes
- Exception message and stack trace:
- Steps to reproduce the issue:"
Hi,
I followed the document https://docs.abp.io/en/abp/4.3/Background-Jobs.
Below is the kind of code sample for your analysis
public async Task<something> MainMethod()
{
// some logic
//
//
//
// some logic
//Here is the code I wanted to run in background
await _backgroundJobManager.EnqueueAsync(
new SomeDto
{
EmailAddress = emailAddress,
Subject = "You've successfully registered!",
Body = "..."
}
);
//Its is inserting 45k records into database.
//I want to run this in background but don't want to wait for this to complete
//Post the above job I am publishing event to notify client about the status.
//return something;
}
public class SomeJob : AsyncBackgroundJob<SomeDto>, ITransientDependency
{
private readonly ISomeInterface _someInterface;
public SomeJob(ISomeInterface someInterface)
{
_someInterface= someInterface;
}
public override async Task SomeMethod(SomeDto args)
{
await _someInterface.SomeOtherMethod(
args.EmailAddress,
args.Subject,
args.Body
);
}
}
The above code works fine on localhost But it doesn't work post-deployment.
There are logs in both methods.
MainMethod()
logs are logged in CloudWatch.
But there is no single log from SomeMethod()
logged in CloudWatch.
I am assuming that this method was not even executed.
I want to know the reason why? How can it get executed on localhost and not on the server?
Also, you got an idea of what I am trying to do. Please suggest a way where I can insert those records in the background without having the request to wait for that code to get executed. The reason is we are using AWS API Gateway, which has a 30-sec limitation. Due to this long insert process, the request gives a timeout error on the angular side.
Alternatively, I tried using https://docs.abp.io/en/abp/4.3/Local-Event-Bus, but this is not executing asynchronously in the background. Also, I tried using https://docs.abp.io/en/abp/4.3/Distributed-Event-Bus, this gets called asynchronously, but here I am stuck in some rabbitMQ object reference null issue.
Please advise !!!
7 Answer(s)
-
0
But it doesn't work post-deployment.
hi
Did you get any error logs? You can use
ILogger
to output some logs.EnqueueAsync
will write a record to the database and return. -
0
But it doesn't work post-deployment.
hi
Did you get any error logs? You can use
ILogger
to output some logs.EnqueueAsync
will write a record to the database and return.Hi, Thank you for your patience.
No there were no errors. Which table do we need to look for?
-
0
hi
No there were no errors.
What about warning logs?
The
AbpBackgroundJobs
table. -
0
Hi,
This is my BackgroundJob
namespace SCV.Litmus.InvoiceManagement.BackgroundJobs { public class QuoteJob : AsyncBackgroundJob<CreateQuoteInputDto>, ITransientDependency { private readonly IQuoteAppService _quoteAppService; public QuoteJob(IQuoteAppService quoteAppService) { _quoteAppService = quoteAppService; } public override async Task ExecuteAsync(CreateQuoteInputDto input) { Log.Information($"QuoteJob.ExecuteAsync started..."); await _quoteAppService.CreateQuoteAsync(input); Log.Information($"QuoteJob.ExecuteAsync ended..."); } } }
And this is the call from an AppService
await _backgroundJobManager.EnqueueAsync(quoteInput);
Logs in the
ExecuteAsync()
were not found in Cloudwatch.Also, there were no warning/error logs found post executing this code
In the AbpBackgroundJobs table, There were no entries in the Tenant_Admin tables But there were 2 entries in the Host_Admin tables PFB screenshot below
Job Arg :
{ "financeAmount": 478943.95, "supplierId": "19a477b0-38e1-45ab-939b-b66812ea6105", "businessEntityId": "fb24fde8-c0a5-4e38-8f4f-27bc17868497", "userId": "fd57be54-05ad-7168-cfb5-39f6066901cf", "invoices": [ { "invoiceId": "3a0b3d47-325c-15b0-a702-907606d81e42", "supplierId": "19a477b0-38e1-45ab-939b-b66812ea6105", "businessEntityId": "fb24fde8-c0a5-4e38-8f4f-27bc17868497", "description": "", "isActive": true, "id": 1340186 }, { "invoiceId": "3a0b3d47-3438-04c2-0395-ef2c7e309305", "supplierId": "19a477b0-38e1-45ab-939b-b66812ea6105", "businessEntityId": "fb24fde8-c0a5-4e38-8f4f-27bc17868497", "description": "", "isActive": true, "id": 1340187 }, { "invoiceId": "3a0b3d47-4fbd-2a6e-63df-b0982c6ca342", "supplierId": "19a477b0-38e1-45ab-939b-b66812ea6105", "businessEntityId": "fb24fde8-c0a5-4e38-8f4f-27bc17868497", "description": "", "isActive": true, "id": 1340188 }, { "invoiceId": "3a0b3824-948a-0366-7881-670d0f2cd185", "supplierId": "19a477b0-38e1-45ab-939b-b66812ea6105", "businessEntityId": "fb24fde8-c0a5-4e38-8f4f-27bc17868497", "description": "", "isActive": true, "id": 1340189 }, { "invoiceId": "3a0b32fc-b6eb-9419-b543-aeaf3dd18c9b", "supplierId": "19a477b0-38e1-45ab-939b-b66812ea6105", "businessEntityId": "fb24fde8-c0a5-4e38-8f4f-27bc17868497", "description": "", "isActive": true, "id": 1340190 } ], "creditNotes": [], "invoiceList": [ { "tenantId": "d1be844b-d3a2-031a-f036-39f5d4380239", "invoiceNumber": "8212395854", "invoiceAdditionalReference": "0700162451", "invoiceUniqueId": "HK08_1000036946_2023_0700162451", "supplierCode": "1000036946", "supplierId": "19a477b0-38e1-45ab-939b-b66812ea6105", "companyCode": "HK08", "currencyId": 1, "description": "Debit Memo", "amount": 39912, "entryDate": "2023-05-17T00:00:00Z", "issueDate": "2023-05-10T00:00:00Z", "dueDate": "2023-08-08T00:00:00Z", "payDate": "0001-01-01T00:00:00Z", "baseLineDate": "2023-05-10T00:00:00Z", "maturityDate": "2023-11-03T00:00:00Z", "erpPostedDate": "0001-01-01T00:00:00Z", "sellerOrganizationId": null, "buyerOrganizationId": null, "netAmount": 0, "eccInvoiceNumber": "9953781495", "fiscalYear": 2023, "statusId": 1, "subStatusId": 0, "isActive": true, "adjustedAmount": 0, "isAdjusted": false, "amountLeftForAdjustment": 39912, "discountDate": "0001-01-01T00:00:00Z", "originalDueDate": "0001-01-01T00:00:00Z", "financingBankBranchId": "00000000-0000-0000-0000-000000000000", "businessEntityId": "00000000-0000-0000-0000-000000000000", "bankReference1": null, "financeTenor": 129, "supplierEntity": "", "isDeleted": false, "deleterId": null, "deletionTime": null, "lastModificationTime": null, "lastModifierId": null, "creationTime": "2023-05-17T19:05:27.397122Z", "creatorId": "39fef723-0723-21e3-2564-1aee5a886074", "id": "3a0b3d47-325c-15b0-a702-907606d81e42" }, { "tenantId": "d1be844b-d3a2-031a-f036-39f5d4380239", "invoiceNumber": "8212395853", "invoiceAdditionalReference": "0700162449", "invoiceUniqueId": "HK08_1000036946_2023_0700162449", "supplierCode": "1000036946", "supplierId": "19a477b0-38e1-45ab-939b-b66812ea6105", "companyCode": "HK08", "currencyId": 1, "description": "Debit Memo", "amount": 39912, "entryDate": "2023-05-17T00:00:00Z", "issueDate": "2023-05-10T00:00:00Z", "dueDate": "2023-08-08T00:00:00Z", "payDate": "0001-01-01T00:00:00Z", "baseLineDate": "2023-05-10T00:00:00Z", "maturityDate": "2023-11-03T00:00:00Z", "erpPostedDate": "0001-01-01T00:00:00Z", "sellerOrganizationId": null, "buyerOrganizationId": null, "netAmount": 0, "eccInvoiceNumber": "9953781494", "fiscalYear": 2023, "statusId": 1, "subStatusId": 0, "isActive": true, "adjustedAmount": 0, "isAdjusted": false, "amountLeftForAdjustment": 39912, "discountDate": "0001-01-01T00:00:00Z", "originalDueDate": "0001-01-01T00:00:00Z", "financingBankBranchId": "00000000-0000-0000-0000-000000000000", "businessEntityId": "00000000-0000-0000-0000-000000000000", "bankReference1": null, "financeTenor": 129, "supplierEntity": "", "isDeleted": false, "deleterId": null, "deletionTime": null, "lastModificationTime": null, "lastModifierId": null, "creationTime": "2023-05-17T19:05:27.872368Z", "creatorId": "39fef723-0723-21e3-2564-1aee5a886074", "id": "3a0b3d47-3438-04c2-0395-ef2c7e309305" }, { "tenantId": "d1be844b-d3a2-031a-f036-39f5d4380239", "invoiceNumber": "8212395855", "invoiceAdditionalReference": "0700162452", "invoiceUniqueId": "HK08_1000036946_2023_0700162452", "supplierCode": "1000036946", "supplierId": "19a477b0-38e1-45ab-939b-b66812ea6105", "companyCode": "HK08", "currencyId": 1, "description": "Debit Memo", "amount": 79823.99, "entryDate": "2023-05-17T00:00:00Z", "issueDate": "2023-05-10T00:00:00Z", "dueDate": "2023-08-08T00:00:00Z", "payDate": "0001-01-01T00:00:00Z", "baseLineDate": "2023-05-10T00:00:00Z", "maturityDate": "2023-11-03T00:00:00Z", "erpPostedDate": "0001-01-01T00:00:00Z", "sellerOrganizationId": null, "buyerOrganizationId": null, "netAmount": 0, "eccInvoiceNumber": "9953781496", "fiscalYear": 2023, "statusId": 1, "subStatusId": 0, "isActive": true, "adjustedAmount": 0, "isAdjusted": false, "amountLeftForAdjustment": 79823.99, "discountDate": "0001-01-01T00:00:00Z", "originalDueDate": "0001-01-01T00:00:00Z", "financingBankBranchId": "00000000-0000-0000-0000-000000000000", "businessEntityId": "00000000-0000-0000-0000-000000000000", "bankReference1": null, "financeTenor": 129, "supplierEntity": "", "isDeleted": false, "deleterId": null, "deletionTime": null, "lastModificationTime": null, "lastModifierId": null, "creationTime": "2023-05-17T19:05:34.917995Z", "creatorId": "39fef723-0723-21e3-2564-1aee5a886074", "id": "3a0b3d47-4fbd-2a6e-63df-b0982c6ca342" }, { "tenantId": "d1be844b-d3a2-031a-f036-39f5d4380239", "invoiceNumber": "8212390700", "invoiceAdditionalReference": "0700152368", "invoiceUniqueId": "HK08_1000036946_2023_0700152368", "supplierCode": "1000036946", "supplierId": "19a477b0-38e1-45ab-939b-b66812ea6105", "companyCode": "HK08", "currencyId": 1, "description": "Debit Memo", "amount": 239471.97, "entryDate": "2023-05-16T00:00:00Z", "issueDate": "2023-05-09T00:00:00Z", "dueDate": "2023-08-07T00:00:00Z", "payDate": "0001-01-01T00:00:00Z", "baseLineDate": "2023-05-09T00:00:00Z", "maturityDate": "2023-11-03T00:00:00Z", "erpPostedDate": "0001-01-01T00:00:00Z", "sellerOrganizationId": null, "buyerOrganizationId": null, "netAmount": 0, "eccInvoiceNumber": "9953767426", "fiscalYear": 2023, "statusId": 1, "subStatusId": 0, "isActive": true, "adjustedAmount": 0, "isAdjusted": false, "amountLeftForAdjustment": 239471.97, "discountDate": "0001-01-01T00:00:00Z", "originalDueDate": "0001-01-01T00:00:00Z", "financingBankBranchId": "00000000-0000-0000-0000-000000000000", "businessEntityId": "00000000-0000-0000-0000-000000000000", "bankReference1": null, "financeTenor": 129, "supplierEntity": "", "isDeleted": false, "deleterId": null, "deletionTime": null, "lastModificationTime": null, "lastModifierId": null, "creationTime": "2023-05-16T19:09:32.69207Z", "creatorId": "39fef723-0723-21e3-2564-1aee5a886074", "id": "3a0b3824-948a-0366-7881-670d0f2cd185" }, { "tenantId": "d1be844b-d3a2-031a-f036-39f5d4380239", "invoiceNumber": "8212384799", "invoiceAdditionalReference": "0700146161", "invoiceUniqueId": "HK08_1000036946_2023_0700146161", "supplierCode": "1000036946", "supplierId": "19a477b0-38e1-45ab-939b-b66812ea6105", "companyCode": "HK08", "currencyId": 1, "description": "Debit Memo", "amount": 79823.99, "entryDate": "2023-05-15T00:00:00Z", "issueDate": "2023-05-06T00:00:00Z", "dueDate": "2023-08-06T00:00:00Z", "payDate": "0001-01-01T00:00:00Z", "baseLineDate": "2023-05-08T00:00:00Z", "maturityDate": "2023-11-03T00:00:00Z", "erpPostedDate": "0001-01-01T00:00:00Z", "sellerOrganizationId": null, "buyerOrganizationId": null, "netAmount": 0, "eccInvoiceNumber": "9953740370", "fiscalYear": 2023, "statusId": 1, "subStatusId": 0, "isActive": true, "adjustedAmount": 0, "isAdjusted": false, "amountLeftForAdjustment": 79823.99, "discountDate": "0001-01-01T00:00:00Z", "originalDueDate": "0001-01-01T00:00:00Z", "financingBankBranchId": "00000000-0000-0000-0000-000000000000", "businessEntityId": "00000000-0000-0000-0000-000000000000", "bankReference1": null, "financeTenor": 129, "supplierEntity": "", "isDeleted": false, "deleterId": null, "deletionTime": null, "lastModificationTime": null, "lastModifierId": null, "creationTime": "2023-05-15T19:07:53.971908Z", "creatorId": "39fef723-0723-21e3-2564-1aee5a886074", "id": "3a0b32fc-b6eb-9419-b543-aeaf3dd18c9b" } ], "creditNotesList": [], "isCreatQuote": true, "isCallFromAutoSubmissionJob": false }
The job was for a tenant in the platform, how come this entry was stored in Host_Admin database and not in Tenant_Admin database ?
Few other questions
- Is there any limitation on what size the job arg can be?
- If Yes, how many records we can pass at a time.
- The activity which I was trying was with small number, but real time numbers may be high.
-
0
hi
The job was for a tenant in the platform, how come this entry was stored in Host_Admin database and not in Tenant_Admin database ?
BackgroundJobsDbContext
always creates and maintains jobs on the Host side.Can you prepare a template project to reproduce? liming.ma@volosoft.com
The
MaxJobArgsLength { get; set; }
is1024 * 1024
, but you can change its length.https://github.com/abpframework/abp/blob/reloadEx/modules/background-jobs/src/Volo.Abp.BackgroundJobs.Domain.Shared/Volo/Abp/BackgroundJobs/BackgroundJobRecordConsts.cs#L13
-
0
Hi maliming
BackgroundJobsDbContext
always creates and maintains jobs on the Host side.How does the job know for which tenant it needs to be executed?
Can you prepare a template project to reproduce? liming.ma@volosoft.com
The project which I am working on is very complicated and not easy to mimic. Please let me know if you can connect over the call to have a look yourself.
The requirement is tenant-specific. Background job needs to be executed for only specific tenants. Not for all tenants, And that too on the trigger of some action.
And why is the
IsAbandoned
field set to false? And I am not sure why the errors were not logged. -
0
The host gets all jobs and executes everyone.
It will
change the current tenant
if theJobArgs
isIMultiTenant