abp icon indicating copy to clipboard operation
abp copied to clipboard

background job not work

Open lee-vic opened this issue 5 years ago • 2 comments

  • 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.

lee-vic avatar Sep 20 '21 03:09 lee-vic

 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);
            });
           
        }
    }

lee-vic avatar Sep 20 '21 03:09 lee-vic

Hi, can you test it like that.

.ContinueWith(async res =>
  {
       await _emailSender.SendAsync(
            args.EmailAddress,
            args.Subject,
            args.Body);
 });

cotur avatar Sep 27 '21 12:09 cotur