/// <summary> /// This is the main entry point for your service instance. /// </summary> /// <param name="cancellationToken">Canceled when Service Fabric needs to shut down this service instance.</param> protected override async Task RunAsync(CancellationToken cancellationToken) { // TODO: Replace the following sample code with your own logic // or remove this RunAsync override if it's not needed in your service. var solutionName = Environment.GetEnvironmentVariable("SolutionName"); var solution = (SolutionName)Enum.Parse(typeof(SolutionName), solutionName); var solutionConfig = SolutionConfigManager.GetSolutionConfig(solution); AppInsightLogger.Initialize(solutionConfig[SolutionConfigName.DASHBOARD_APP_INSIGHT_KEY].ToString()); long iterations = 0; var backendWorker = MetricCollectorWorkerFactory.GetMetricCollectorWorker(solution, solutionConfig); while (true) { AppInsightLogger.Instance.TraceIteration(); cancellationToken.ThrowIfCancellationRequested(); ServiceEventSource.Current.ServiceMessage(this.Context, "Working-{0}", ++iterations); try { backendWorker.CollectMetrics(); } catch (Exception ex) { AppInsightLogger.Instance.Error(ex); } await Task.Delay(TimeSpan.FromMinutes(3), cancellationToken); } }
public static void Run([TimerTrigger("0 0 6 1/1 * * ", RunOnStartup = true)] TimerInfo myTimer, TraceWriter log, ExecutionContext context) { var logger = new AppInsightLogger(); try { var settingsProvider = new SettingsProvider(context.FunctionAppDirectory, "Values"); logger.LogInfo($"C# Timer trigger function executing at: {DateTime.Now}"); var processor = new EventsProcessor(new TableStorage <Event>("Events", settingsProvider.GetSetting("StorageAccountConnectionString")), new NotificationChannelFactory(settingsProvider)); processor.ProcessEvents(); logger.LogInfo($"C# Timer trigger function executed at: {DateTime.Now}"); } catch (Exception ex) { logger.LogException(ex); } }