Base solution for your next web application
Open Closed

Problem sending expire edition email 2 times #10685


User avatar
0
QuickApp created

What is your product version? v10.2.0 What is your product type (Angular or MVC)? Angular What is product framework type (.net framework or .net core)? .Net Core

Hi, SubscriptionExpireEmailNotifierWorker class sends mail 10 days before the edition expires. But it sends the same e-mail 2 times with an interval of 1-2 hours.

I couldn't understand what the problem is, the codes are as follows:

using System;
using System.Diagnostics;
using Abp.Configuration;
using Abp.Dependency;
using Abp.Domain.Repositories;
using Abp.Threading;
using Abp.Threading.BackgroundWorkers;
using Abp.Threading.Timers;
using Abp.Timing;
using QCloud.Authorization.Users;
using QCloud.Configuration;

namespace QCloud.MultiTenancy
{
    public class SubscriptionExpireEmailNotifierWorker : PeriodicBackgroundWorkerBase, ISingletonDependency
    {
        private const int CheckPeriodAsMilliseconds = 1 * 60 * 60 * 1000 * 24; //1 day
        
        private readonly IRepository<Tenant> _tenantRepository;
        private readonly UserEmailer _userEmailer;

        public SubscriptionExpireEmailNotifierWorker(
            AbpTimer timer,
            IRepository<Tenant> tenantRepository,
            UserEmailer userEmailer) : base(timer)
        {
            _tenantRepository = tenantRepository;
            _userEmailer = userEmailer;

            Timer.Period = CheckPeriodAsMilliseconds;
            Timer.RunOnStart = true;

            LocalizationSourceName = QCloudConsts.LocalizationSourceName;
        }

        protected override void DoWork()
        {
            var subscriptionRemainingDayCount = Convert.ToInt32(SettingManager.GetSettingValueForApplication(AppSettings.TenantManagement.SubscriptionExpireNotifyDayCount));
            var dateToCheckRemainingDayCount = Clock.Now.AddDays(subscriptionRemainingDayCount).ToUniversalTime();

            var subscriptionExpiredTenants = _tenantRepository.GetAllList(
                tenant => tenant.SubscriptionEndDateUtc != null &&
                          tenant.SubscriptionEndDateUtc.Value.Date == dateToCheckRemainingDayCount.Date &&
                          tenant.IsActive &&
                          tenant.EditionId != null
            );

            foreach (var tenant in subscriptionExpiredTenants)
            {
                Debug.Assert(tenant.EditionId.HasValue);
                try
                {
                    AsyncHelper.RunSync(() => _userEmailer.TrialIsAboutToExpire(tenant.Id, dateToCheckRemainingDayCount,(int)tenant.EditionId));
                }
                catch (Exception exception)
                {
                    Logger.Error(exception.Message, exception);
                }
            }
        }
    }
}

3 Answer(s)
  • User Avatar
    0
    musa.demir created

    Hi @QuickApp

    We will investigate it. You can follow progress in https://github.com/aspnetzero/aspnet-zero-core/issues/4111

  • User Avatar
    0
    QuickApp created

    Hi @musa.demir I will follow the situation from the relevant link, thanks.

  • User Avatar
    0
    musa.demir created

    Hi @QuickApp

    I could not reproduce it in my local pc. Do you host your application in multiple instances? That might be the reason. If you have multiple instance of your application we may suggest you to use hangfire for jobs. Here is the implementation document https://aspnetboilerplate.com/Pages/Documents/Hangfire-Integration