/// <summary> /// Starts the job fetcher /// </summary> public static void Start() { Log.Verbose("Starting EmailJob Fetcher"); int fetchIntervalVal; if (int.TryParse(CloudConfigurationManager.GetSetting(MerchantEmailJobFetchIntervalInMinutes), out fetchIntervalVal)) { _merchantEmailJobsFetchInterval = fetchIntervalVal * 60 * 1000; } else { _merchantEmailJobsFetchInterval = 60 * 60 * 1000; } _transactionReportSubject = CloudConfigurationManager.GetSetting(MerchantTransactionReportSubject); _transactionReportCampaign = CloudConfigurationManager.GetSetting(MerchantTransactionReportCampaign); string storageAccount = CloudConfigurationManager.GetSetting(StorageSetting); string emailJobsQueueName = CloudConfigurationManager.GetSetting(EmailJobsQueueNameSetting); string userDalConnectionString = CloudConfigurationManager.GetSetting(UsersDalConnectionStringSetting); Log.Verbose("Finished reading settings"); _usersDal = new UsersDal(userDalConnectionString); _emailJobsQueue = new JobsQueue <EmailCargo>(storageAccount, emailJobsQueueName); Log.Verbose("Instantiated Users dal and Email Jobs queue"); _merchantJobtimer = new Timer(callback => GetJob(), null, 0, _merchantEmailJobsFetchInterval); Log.Verbose("Created merchant email jobs timer with the interval set to {0} minutes", _merchantEmailJobsFetchInterval.ToString()); }
/// <summary> /// Bootstraps the job agents /// </summary> /// <param name="idPrefix"> /// The agent id Prefix. /// </param> /// <returns> /// List of instantiaged job processors /// </returns> public IEnumerable <IJobProcessor> Bootstrap(string idPrefix) { int jobProcessorCount = int.Parse(CloudConfigurationManager.GetSetting(JobsProcessorCountSetting)); Log.Verbose("Mailing Manager. Bootstrap Start - agents number = {0}", jobProcessorCount); string storageSetting = CloudConfigurationManager.GetSetting(StorageSetting); string emailJobsQueueName = CloudConfigurationManager.GetSetting(EmailJobsQueueNameSetting); //Initialize the jobs queue IJobsQueue <EmailCargo> emailJobsQueue = new JobsQueue <EmailCargo>(storageSetting, emailJobsQueueName); IPriorityEmailJobsQueue <PriorityEmailCargo> priorityEmailJobsQueue = new PriorityEmailJobsQueue <PriorityEmailCargo>(); //Initialize the Merchant Email handler IEmailJobHandler merchantEmailJobHandler = new MerchantEmailJobHandler(); merchantEmailJobHandler.Initialize(); //Initialize the Deals Email handler IEmailJobHandler dealsEmailJobHandler = new DealsEmailJobHandler(); dealsEmailJobHandler.Initialize(); //Initialize the Remainder Email handler IEmailJobHandler remainderMailHandler = new RemainderEmailJobHandler(); remainderMailHandler.Initialize(); //Initialize the Campaign Email handler IEmailJobHandler campaignEmailJobHandler = new CampaignEmailJobHandler(); campaignEmailJobHandler.Initialize(); //Initialize the Priority Email handler IPriorityEmailJobHandler confirmationEmailHandler = new ConfirmationEmailJobHandler(); confirmationEmailHandler.Initialize(); //TODO: Having a different emailhandler and emailcargo for priority email is not right. // The priority email handler and priority email cargo should be of type IEmailJobHandler and EmailCargo respectively // This change has to be done once the users dal is decoupled out of commerce and merchant. We could then have all the jobs and their cargo inside // userservicesstorage. //Register the handlers Dictionary <Type, object> jobHandlers = new Dictionary <Type, object> { { typeof(MerchantReportEmailCargo), merchantEmailJobHandler }, { typeof(DealsEmailCargo), dealsEmailJobHandler }, { typeof(ConfirmationEmailCargo), confirmationEmailHandler }, { typeof(PromotionalEmailCargo), remainderMailHandler }, { typeof(CampaignEmailCargo), campaignEmailJobHandler } }; List <EmailJobProcessor> agents = new List <EmailJobProcessor>(); for (int i = 0; i < jobProcessorCount; i++) { EmailJobProcessor agent = new EmailJobProcessor(idPrefix + "_" + i, emailJobsQueue, priorityEmailJobsQueue, jobHandlers); agents.Add(agent); } Log.Verbose("Mailing Manager. Bootstrap Completed - agents number = {0}", jobProcessorCount); return(agents); }