public async Task Run() { if (!_twinCollection.Contains(Constants.TwinKeys.Module)) { await Console.Out.WriteLineAsync("Module not defined"); return; } JObject module = _twinCollection[Constants.TwinKeys.Module]; _jobDependencies.Module.State = (ModuleState)module.SelectToken(Constants.TwinKeys.ModuleState).Value <Int32>(); var desiredPublisherIds = new List <string>(); foreach (JProperty item in module.Children().Where(i => i.Path.Contains(Constants.TwinKeys.PublisherPrefix))) { desiredPublisherIds.Add(item.Name.Replace(Constants.TwinKeys.PublisherPrefix, string.Empty)); var publisher = ReconcilePublisher(item); } foreach (var publisher in _jobDependencies.Module.Publishers.Where(i => !desiredPublisherIds.Contains(i.Id))) { publisher.DesiredState = DesiredPublisherState.Removed; } var routingJob = new RoutingJob(_jobDependencies); await routingJob.Run(); var reportedJob = new ReportedPropertyUpdateJob(_jobDependencies); await reportedJob.Run(); }
public async Task Run() { var existing = _jobDependencies.Module.Publishers.FirstOrDefault(i => i.SubscriptionId == _publisherHeartbeat.SubscriptionId); if (existing == default) { Console.Out.WriteLine("Heartbeat was received from an unknown subscription id"); return; } Console.Out.WriteLine($"Heartbeat was received for publisher id: {existing.Id}"); existing.LastMessageTime = DateTimeOffset.UtcNow; if (existing.ActualState != ActualPublisherState.Healthy) { existing.ActualState = ActualPublisherState.Healthy; var reportedPropertyJob = new ReportedPropertyUpdateJob(_jobDependencies); await reportedPropertyJob.Run(); } }