Beispiel #1
0
        public void Run()
        {
            LogManager.Log.Info("WorkerRole.Run Loop Started");

            using (IOutgoingSmsQueue outgoing = OutgoingSmsQueue.GetInstance())
            {
                outgoing.Send(OutgoingSmsMessage.CreateWithDefaults(_Configuration.AdminNumber,
                                                                    "WorkerRole.Run Loop Started"),
                              null,
                              null);

                while (true)
                {
                    // waiting for the queue to drain ensures we won't pick up the same one twice
                    if (outgoing.Length == 0)
                    {
                        IDataStore store = DataStore.GetInstance();

                        ProcessOutgoingMessages(outgoing, store);
                        ProcessSubscriptions(outgoing, store);
                    }
                    else
                    {
                        // there is already a back-log do don't go adding more to it...
                        Thread.Sleep(5 * 1000);
                    }
                }
            }
        }
Beispiel #2
0
        public override bool OnStart()
        {
            // Set the maximum number of concurrent connections
            ServicePointManager.DefaultConnectionLimit = 12;

            try
            {
                CreateServiceHost();
                LogManager.Log.Info("WCF Services started");
            }
            catch (Exception ex)
            {
                LogManager.Log.Error("Exception configuring WCF Services", ex);

                using (IOutgoingSmsQueue outgoing = OutgoingSmsQueue.GetInstance())
                {
                    IConfiguration config = Configuration.GetInstance();
                    outgoing.Send(OutgoingSmsMessage.CreateWithDefaults(config.AdminNumber,
                                                                        "WCF STARTUP ERROR: " + ex.GetType().FullName),
                                  null,
                                  null);
                }
            }

            return(base.OnStart());
        }
Beispiel #3
0
        private void ProcessOutgoingMessages(IOutgoingSmsQueue outgoing, IDataStore store)
        {
            // first check the messages that were never attempted sorted by oldest to newest
            IList <OutgoingSmsMessage> messages = store.OutgoingMessages
                                                  .Where(m => m.NextAttempt < DateTime.UtcNow)
                                                  .OrderBy(m => m.UtcWhenAdded)
                                                  .Take(outgoing.MessagesPerMinute)
                                                  .ToList();

            // queue them
            foreach (OutgoingSmsMessage msg in messages)
            {
                outgoing.Send(msg, MessageSent, MessageSendThrewException);
            }
        }
Beispiel #4
0
        private static void ProcessSubscriptions(IOutgoingSmsQueue outgoing, IDataStore store)
        {
            DailyIdea idea = DailyIdea.TodaysIdea(DateTime.Today.ToUniversalTime());
            if (idea != null)
            {
                // now deal with the existing subscriptions
                // all where doing here is creating entries in the OutgoingSmsMessage table and updating the Next field on the
                // Subscription.  These will be picked up on the next pass through the loop by the message sender.
                IList<Subscription> toProcess = store.Subscriptions.Where(s => s.Next < DateTime.UtcNow)
                    .Take(outgoing.MessagesPerMinute)
                    .ToList();

                foreach (Subscription sub in toProcess)
                {
                    OutgoingSmsMessage msg = OutgoingSmsMessage.CreateWithDefaults(sub.Phone, idea.Idea);
                    store.ScheduleMessage(msg, sub);
                }
            }
        }
Beispiel #5
0
        private static void ProcessSubscriptions(IOutgoingSmsQueue outgoing, IDataStore store)
        {
            DailyIdea idea = DailyIdea.TodaysIdea(DateTime.Today.ToUniversalTime());

            if (idea != null)
            {
                // now deal with the existing subscriptions
                // all where doing here is creating entries in the OutgoingSmsMessage table and updating the Next field on the
                // Subscription.  These will be picked up on the next pass through the loop by the message sender.
                IList <Subscription> toProcess = store.Subscriptions.Where(s => s.Next < DateTime.UtcNow)
                                                 .Take(outgoing.MessagesPerMinute)
                                                 .ToList();

                foreach (Subscription sub in toProcess)
                {
                    OutgoingSmsMessage msg = OutgoingSmsMessage.CreateWithDefaults(sub.Phone, idea.Idea);
                    store.ScheduleMessage(msg, sub);
                }
            }
        }
Beispiel #6
0
        private void ProcessOutgoingMessages(IOutgoingSmsQueue outgoing, IDataStore store)
        {
            // first check the messages that were never attempted sorted by oldest to newest
            IList<OutgoingSmsMessage> messages = store.OutgoingMessages
                .Where(m => m.NextAttempt < DateTime.UtcNow)
                .OrderBy(m => m.UtcWhenAdded)
                .Take(outgoing.MessagesPerMinute)
                .ToList();

            // queue them
            foreach (OutgoingSmsMessage msg in messages)
            {
                outgoing.Send(msg, MessageSent, MessageSendThrewException);
            }
        }