func handleMessage(msg consumer.Message) { tid := msg.Headers["X-Request-Id"] log.Debugf("Received message with TID [%v]", tid) if isSyntheticMessage(tid) { log.Debugf("Message [%v] is a synthetic publication, skipping...", tid) return } publishedContent, err := content.UnmarshalContent(msg) if err != nil { log.Warnf("Cannot unmarshal message [%v], error: [%v]", tid, err.Error()) return } uuid := publishedContent.GetUUID() if !publishedContent.IsValid() { log.Infof("Message [%v] with UUID [%v] is INVALID, skipping...", tid, uuid) return } publishDateString := msg.Headers["Message-Timestamp"] publishDate, err := time.Parse(dateLayout, publishDateString) if err != nil { log.Errorf("Cannot parse publish date [%v] from message [%v], error: [%v]", publishDateString, tid, err.Error()) return } log.Infof("Content published, uuid=%s, publishDate=%v", uuid, publishDate) //TODO work out if it's been created, updated or deleted (use //publishedContent.IsMarkedDeleted() //TODO get the headline (which I don't think is available - change the content package??) //TODO get the REAL publish date if publishedContent.GetType() != "Image" { notifySlack(uuid, tid, publishDateString) } }
func handleMessage(msg consumer.Message) { tid := msg.Headers["X-Request-Id"] infoLogger.Printf("Received message with TID [%v]", tid) if isIgnorableMessage(tid) { infoLogger.Printf("Message [%v] is ignorable. Skipping...", tid) return } publishedContent, err := content.UnmarshalContent(msg) if err != nil { warnLogger.Printf("Cannot unmarshal message [%v], error: [%v]", tid, err.Error()) return } uuid := publishedContent.GetUUID() contentType := publishedContent.GetType() var validationEndpoint string var found bool var username string var password string if validationEndpoint, found = appConfig.ValidationEndpoints[contentType]; found { username, password = getValidationCredentials(validationEndpoint) } if !publishedContent.IsValid(validationEndpoint, username, password) { infoLogger.Printf("Message [%v] with UUID [%v] is INVALID, skipping...", tid, uuid) return } infoLogger.Printf("Message [%v] with UUID [%v] is VALID.", tid, uuid) publishDateString := msg.Headers["Message-Timestamp"] publishDate, err := time.Parse(dateLayout, publishDateString) if err != nil { errorLogger.Printf("Cannot parse publish date [%v] from message [%v], error: [%v]", publishDateString, tid, err.Error()) return } if isMessagePastPublishSLA(publishDate, appConfig.Threshold) { infoLogger.Printf("Message [%v] with UUID [%v] is past publish SLA, skipping.", tid, uuid) return } scheduleChecks(publishedContent, publishDate, tid, publishedContent.IsMarkedDeleted(), &metricContainer, environments) // for images we need to check their corresponding image sets // the image sets don't have messages of their own so we need to create one if publishedContent.GetType() == "Image" { eomFile, ok := publishedContent.(content.EomFile) if !ok { errorLogger.Printf("Cannot assert that message [%v] with UUID [%v] and type 'Image' is an EomFile.", tid, uuid) return } imageSetEomFile := spawnImageSet(eomFile) if imageSetEomFile.UUID != "" { scheduleChecks(imageSetEomFile, publishDate, tid, false, &metricContainer, environments) } } }