public async Task <IActionResult> PublishSecondaryReportNotificationAsync(string iaocCode, string reportPeriod, int year, string message) { var topic = _configuration.GetValue <string>("TopicSecondaryReportNotification"); try { var notification = new ReportNotification { AirlineICAOCode = iaocCode, ReportingPeriod = reportPeriod, ReportDateUTC = new DateTime(year, 1, 1), Message = message }; var payload = Newtonsoft.Json.JsonConvert.SerializeObject(notification); var response = await _messagePublisher.PublishNotificationAsync(topic, payload); if (response) { return(Ok()); } } catch (Exception ex) { _logger.LogCritical(ex, "FAILED trying to Publish Secondary Report Notification", iaocCode, reportPeriod, message); } return(BadRequest()); }
/// <summary> /// Publish Secondary Report Notification when All Primary reports are available /// </summary> /// <param name="airlineCode">Airline ICAO Code</param> /// <param name="reportPeriod">Annual, Qn, Hn</param> /// <param name="currency">Currency</param> /// <param name="year">Year</param> /// <returns>Notification Response</returns> public async Task <NotificationActionResponse> TestAndPublishSecondaryReportNotificationAsync(string airlineCode, string reportPeriod, string currency, int year) { var response = new NotificationActionResponse { Topic = _secondaryReportNotificationTopic }; try { var allCoreReportsAvailable = await _reportDataService.TestAllCoreReportsAvailableAsync(airlineCode, reportPeriod, year); if (!allCoreReportsAvailable) { var message = "Start Secondary Report Generation!"; var notification = new ReportNotification { AirlineICAOCode = airlineCode, ReportingPeriod = reportPeriod, Currency = currency, Message = message }; var payload = Newtonsoft.Json.JsonConvert.SerializeObject(notification); response.MessagePublished = await _messagePublisher.PublishNotificationAsync(_secondaryReportNotificationTopic, payload); } } catch (Exception ex) { response.FaultMessage = ex.Message; _logger.LogCritical(ex, airlineCode, reportPeriod, currency, year); } return(response); }