Пример #1
0
        public string Get()
        {
            try
            {
                var estTimeZone = TimeZoneInfo.FindSystemTimeZoneById(appsettings.JobSchedules.TimeZone);

                var manager = new RecurringJobManager();

                manager.AddOrUpdate("Deporter", Job.FromExpression(() => dep.Execute()),
                                    appsettings.JobSchedules.Deporter, estTimeZone, HangfireQueue.deporter.ToString());

                manager.AddOrUpdate("TitleSync", Job.FromExpression(() => tsy.Execute()),
                                    appsettings.JobSchedules.TitleSync, estTimeZone, HangfireQueue.titlesync.ToString());

                manager.AddOrUpdate("MailBox", Job.FromExpression(() => mbx.Execute()),
                                    appsettings.JobSchedules.MailBox, estTimeZone, HangfireQueue.mailbox.ToString());

                manager.AddOrUpdate("CloudAmqpSync", Job.FromExpression(() => cloudAmqpSync.Execute()),
                                    appsettings.JobSchedules.CloudAmqpSync, estTimeZone, HangfireQueue.titlesync.ToString());

                foreach (var activeQueue in queueService.GetByStatus(true))
                {
                    if (activeQueue.FriendlyName.ToLower().StartsWith("unittest") && activeQueue.ContactEmailAddress.ToLower().Equals("*****@*****.**"))
                    {
                        manager.AddOrUpdate(string.Format("Publisher-{0}", activeQueue.Name),
                                            Job.FromExpression(() => pub.Execute(activeQueue.Name)), appsettings.JobSchedules.Deporter, estTimeZone, HangfireQueue.publisher.ToString());
                    }
                    else
                    {
                        manager.AddOrUpdate(string.Format("Publisher-{0}", activeQueue.Name),
                                            Job.FromExpression(() => pub.Execute(activeQueue.Name)), appsettings.JobSchedules.Publisher, estTimeZone, HangfireQueue.publisher.ToString());
                    }
                }

                return("Successfully registered jobs");
            }
            catch (Exception e)
            {
                logger.Error(e, "Error while registering Jobs");
                throw e;
            }
        }