// On Timer, grab items from RSS Feed public void RSSFeedProcessor( [TimerTrigger("0 */5 * * * *", RunOnStartup=true)] TimerInfo timer, [Queue("SaveQuestions")] ICollector<Question> outQ, TraceWriter log) { log.Verbose("RSS Feed Processor started"); Console.WriteLine("RSS Feed Processor started"); foreach (var feeds in mFeedSources) { switch(feeds.Key){ case "StackOverflow": foreach (var feed in feeds.Value) { try { using (XmlReader reader = XmlReader.Create(feed.Value)) { SyndicationFeed rss = SyndicationFeed.Load(reader); foreach (SyndicationItem item in rss.Items) { outQ.Add(ProcessStackOverflowEntry(item, feed.Key)); } } } catch (Exception e) { log.Error(String.Format("Couldn't read from feed - {0}", feeds.Value), e); } } break; default: log.Warning(String.Format("Couldn't recognize feed format: {0}", feeds.Key),"RSSFeedProcessor"); break; } } }
public async Task <bool> RenewAsync(TraceWriter trace, ILogger logger, CancellationToken cancellationToken) { try { AccessCondition condition = new AccessCondition { LeaseId = this.LeaseId }; DateTimeOffset requestStart = DateTimeOffset.UtcNow; await this.Blob.RenewLeaseAsync(condition, null, null, cancellationToken); _lastRenewal = DateTime.UtcNow; _lastRenewalLatency = _lastRenewal - requestStart; // The next execution should occur after a normal delay. return(true); } catch (StorageException exception) { if (exception.IsServerSideError()) { string msg = string.Format(CultureInfo.InvariantCulture, "Singleton lock renewal failed for blob '{0}' with error code {1}.", this.LockId, FormatErrorCode(exception)); trace.Warning(msg, source: TraceSource.Execution); logger?.LogWarning(msg); return(false); // The next execution should occur more quickly (try to renew the lease before it expires). } else { // Log the details we've been accumulating to help with debugging this scenario int leasePeriodMilliseconds = (int)_leasePeriod.TotalMilliseconds; string lastRenewalFormatted = _lastRenewal.ToString("yyyy-MM-ddTHH:mm:ss.FFFZ", CultureInfo.InvariantCulture); int millisecondsSinceLastSuccess = (int)(DateTime.UtcNow - _lastRenewal).TotalMilliseconds; int lastRenewalMilliseconds = (int)_lastRenewalLatency.TotalMilliseconds; string msg = string.Format(CultureInfo.InvariantCulture, "Singleton lock renewal failed for blob '{0}' with error code {1}. The last successful renewal completed at {2} ({3} milliseconds ago) with a duration of {4} milliseconds. The lease period was {5} milliseconds.", this.LockId, FormatErrorCode(exception), lastRenewalFormatted, millisecondsSinceLastSuccess, lastRenewalMilliseconds, leasePeriodMilliseconds); trace.Error(msg); logger?.LogError(msg); // If we've lost the lease or cannot re-establish it, we want to fail any // in progress function execution throw; } } }
public async Task <TaskSeriesCommandResult> ExecuteAsync(CancellationToken cancellationToken) { TimeSpan delay; try { AccessCondition condition = new AccessCondition { LeaseId = _leaseId }; DateTimeOffset requestStart = DateTimeOffset.UtcNow; await _leaseBlob.RenewLeaseAsync(condition, null, null, cancellationToken); _lastRenewal = DateTime.UtcNow; _lastRenewalLatency = _lastRenewal - requestStart; // The next execution should occur after a normal delay. delay = _speedupStrategy.GetNextDelay(executionSucceeded: true); } catch (StorageException exception) { if (exception.IsServerSideError()) { // The next execution should occur more quickly (try to renew the lease before it expires). delay = _speedupStrategy.GetNextDelay(executionSucceeded: false); _trace.Warning(string.Format(CultureInfo.InvariantCulture, "Singleton lock renewal failed for blob '{0}' with error code {1}. Retry renewal in {2} milliseconds.", _lockId, FormatErrorCode(exception), delay.TotalMilliseconds), source: TraceSource.Execution); } else { // Log the details we've been accumulating to help with debugging this scenario int leasePeriodMilliseconds = (int)_leasePeriod.TotalMilliseconds; string lastRenewalFormatted = _lastRenewal.ToString("yyyy-MM-ddTHH:mm:ss.FFFZ", CultureInfo.InvariantCulture); int millisecondsSinceLastSuccess = (int)(DateTime.UtcNow - _lastRenewal).TotalMilliseconds; int lastRenewalMilliseconds = (int)_lastRenewalLatency.TotalMilliseconds; _trace.Error(string.Format(CultureInfo.InvariantCulture, "Singleton lock renewal failed for blob '{0}' with error code {1}. The last successful renewal completed at {2} ({3} milliseconds ago) with a duration of {4} milliseconds. The lease period was {5} milliseconds.", _lockId, FormatErrorCode(exception), lastRenewalFormatted, millisecondsSinceLastSuccess, lastRenewalMilliseconds, leasePeriodMilliseconds)); // If we've lost the lease or cannot re-establish it, we want to fail any // in progress function execution throw; } } return(new TaskSeriesCommandResult(wait: Task.Delay(delay))); }
public void Warning(string message) { _logger.Warning(message); }