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