/// <summary> /// Services that want to implement a processing loop which runs /// when it is primary and has write status, just override this method with their logic /// </summary> /// <param name="cancellationToken">Cancellation token to monitor for cancellation requests.</param> /// <returns>A Task that represents outstanding operation.</returns> protected override async Task RunAsync(CancellationToken cancellationToken) { ServiceEventSource.Current.ServiceMessage(this.Context, "RunAsync called"); ServiceEventSource.Current.Trace($"RunAsync INFO: RunnAsync called.."); // Check if settings are null. If they are, throw. if (null == this.Settings) { ServiceEventSource.Current.Trace($"RunAsync ERROR: settings are null..."); throw new ArgumentNullException("Settings are null, check Config/Settings exist."); } // Create the operations classes. ServiceEventSource.Current.Trace($"RunAsync INFO: creating the telemetry class"); this._telemetry = new AiTelemetry(this.GetConfigValueAsString(WatchdogConfigSectionName, "AIKey")); ServiceEventSource.Current.Trace($"RunAsync INFO: creating the metrics class"); this._metricsOperations = new MetricsOperations( this, this._telemetry, this.GetConfigValueAsTimeSpan(WatchdogConfigSectionName, "MetricInterval", TimeSpan.FromMinutes(5)), cancellationToken); // COMMENTED //this._cleanupOperations = new CleanupOperations(this._telemetry, TimeSpan.FromMinutes(2), cancellationToken) //{ // Endpoint = this.GetConfigValueAsString(WatchdogConfigSectionName, "DiagnosticEndpoint"), // SasToken = this.GetConfigValueAsString(WatchdogConfigSectionName, "DiagnosticSasToken"), // TimeToKeep = this.GetConfigValueAsTimeSpan(WatchdogConfigSectionName, "DiagnosticTimeToKeep", TimeSpan.FromDays(10)), // TimerInterval = this.GetConfigValueAsTimeSpan(WatchdogConfigSectionName, "DiagnosticInterval", TimeSpan.FromMinutes(2)) //}; ServiceEventSource.Current.Trace($"RunAsync INFO: creating the healthcheck operation class"); this._healthCheckOperations = new HealthCheckOperations( this, this._telemetry, this.GetConfigValueAsTimeSpan(WatchdogConfigSectionName, "HealthCheckInterval", TimeSpan.FromMinutes(5)), cancellationToken); // Register the watchdog health check. ServiceEventSource.Current.Trace($"RunAsync:RegisterHealthCheckAsync INFO: RegisterHealthCheckAsync called..."); await this.RegisterHealthCheckAsync(cancellationToken).ConfigureAwait(false); // Loop waiting for cancellation. while (false == cancellationToken.IsCancellationRequested) { // Report the health and metrics of the watchdog to Service Fabric. ServiceEventSource.Current.Trace($"RunAsync:ReportWatchdogHealth INFO: ReportWatchdogHealth called..."); this.ReportWatchdogHealth(); ServiceEventSource.Current.Trace($"RunAsync:ReportWatchdogMetricsAsync INFO: ReportWatchdogMetricsAsync called..."); await this.ReportWatchdogMetricsAsync(cancellationToken); ServiceEventSource.Current.Trace($"RunAsync:ReportClusterHealthAsync INFO: ReportClusterHealthAsync called..."); await this.ReportClusterHealthAsync(cancellationToken); // Delay up to the time for the next health report. await Task.Delay(this.HealthReportInterval, cancellationToken); } }
/// <summary> /// This is the main entry point for your service replica. /// This method executes when this replica of your service becomes primary and has write status. /// </summary> /// <param name="cancellationToken">Canceled when Service Fabric needs to shut down this service replica.</param> protected override async Task RunAsync(CancellationToken cancellationToken) { ServiceEventSource.Current.ServiceMessage(this.Context, "RunAsync called"); _context = this.Context; _settings = this.Context.CodePackageActivationContext.GetConfigurationPackageObject("Config").Settings; // Check if settings are null. If they are, throw. if (null == this.Settings) { throw new ArgumentNullException("Settings are null, check Config/Settings exist."); } // Create the operations classes. this._healthCheckOperations = new HealthCheckOperations( this, this._telemetry, this.GetConfigValueAsTimeSpan(WatchdogConfigSectionName, "HealthCheckInterval", TimeSpan.FromMinutes(5)), cancellationToken); // Register the watchdog health check. await this.RegisterHealthCheckAsync(cancellationToken).ConfigureAwait(false); // Loop waiting for cancellation. while (false == cancellationToken.IsCancellationRequested) { // Report the health and metrics of the watchdog to Service Fabric. this.ReportWatchdogHealth(); // TODO: we removed telemetry because this is using applicationinsight which is not available for us //await this.ReportWatchdogMetricsAsync(cancellationToken); // Delay up to the time for the next health report. await Task.Delay(this.HealthReportInterval, cancellationToken); } }