abp
abp copied to clipboard
background job not work
- Your ABP Framework version 4.4.2
- Your User Interface MVC
- Your database provider:EF Core
I follow the tutorial: https://docs.abp.io/en/abp/latest/Background-Jobs for testing,It's weird. Sometimes it works, sometimes it doesn't.I look at the data in the database for table AbpBackgroundJobs. Column IsAbandoned has the value true. I don't understand, because the tutorial instructions will only be abandoned after the timeout.
public class TestAppService : OrchidAppService
{
private readonly IBackgroundJobManager _backgroundJobManager;
public TestAppService(IBackgroundJobManager backgroundJobManager)
{
_backgroundJobManager = backgroundJobManager;
}
public async Task GetListAsync()
{
await _backgroundJobManager.EnqueueAsync(
new EmailSendingArgs
{
EmailAddress = "[email protected]",
Subject = "You've successfully registered!",
Body = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
}
);
}
}
public class EmailSendingJob : AsyncBackgroundJob<EmailSendingArgs>, ITransientDependency
{
private readonly IEmailSender _emailSender;
public EmailSendingJob(IEmailSender emailSender)
{
_emailSender = emailSender;
}
public override async Task ExecuteAsync(EmailSendingArgs args)
{
await Task.Delay(1000 * 20).ContinueWith(res=> {
_emailSender.SendAsync(
args.EmailAddress,
args.Subject,
args.Body);
});
}
}
Hi, can you test it like that.
.ContinueWith(async res =>
{
await _emailSender.SendAsync(
args.EmailAddress,
args.Subject,
args.Body);
});