Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
anthony-britton-moj authored Jan 29, 2024
1 parent 9cfb990 commit bb4c0d9
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 11 deletions.
88 changes: 88 additions & 0 deletions .github/workflows/reports.yml
Original file line number Diff line number Diff line change
Expand Up @@ -179,5 +179,93 @@ jobs:
with:
channel-id: topic-pi-approved-premises
payload: ${{ steps.transform.outputs.result }}
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}

refer-and-monitor-failures:
runs-on: ubuntu-latest
steps:
- name: Search app insights
id: search
run: |
echo "result=$(curl -fsSL -H "x-api-key: $key" --data-urlencode "query=$query" --get "$url")" | tee -a "$GITHUB_OUTPUT"
env:
url: https://api.applicationinsights.io/v1/apps/${{ secrets.APP_INSIGHTS_APPLICATION_GUID }}/query
key: ${{ secrets.APP_INSIGHTS_API_KEY }}
query: |
customEvents
| where timestamp > ago(7d) and timestamp < now()
| where cloud_RoleName in ("refer-and-monitor-and-delius")
| where name in ("ReferAndMonitorFailureReport")
| project customDimensions.crn, customDimensions.message, itemId, timestamp
| order by tostring(customDimensions_crn) asc
- name: Transform results into Slack message
id: transform
if: fromJson(steps.search.outputs.result).tables[0].rows[0] != null
run: |
echo "result=$(echo "$search_result" | jq -rc '.tables[0].rows |
{
"blocks": ([
{
"type": "header",
"text": {
"type": "plain_text",
"text": ":information_source: Refer and Monitor Processing Failures"
}
},
{
"type": "section",
"text": {
"type": "plain_text",
"text": "The following cases failed to process in Delius over the last 7 days. Please check and manually correct the cases if required."
},
"fields": [
{
"type": "mrkdwn",
"text": "*CRN*"
},
{
"type": "mrkdwn",
"text": "*Reason*"
}
]
}
] +
(. | [_nwise(5)] | map({
"type": "section",
"fields": (. | map([
{
type: "plain_text",
text: .[0]
},
{
type: "mrkdwn",
text: (.[1] + " (<https://portal.azure.com/#blade/AppInsightsExtension/DetailsV2Blade/DataModel/%7B%22eventId%22:%22" + .[2] + "%22,%22timestamp%22:%22" + .[3] + "%22%7D/ComponentId/%7B%22Name%22:%22nomisapi-prod%22,%22ResourceGroup%22:%22nomisapi-prod-rg%22,%22SubscriptionId%22:%22${{ secrets.APP_INSIGHTS_SUBSCRIPTION_ID }}%22%7D|Details>).")
}
]) | flatten)
})) +
[
{
"type": "context",
"elements": [
{
"type": "mrkdwn",
"text": ">This report was generated automatically. For more information, contact the probation integration team."
}
]
}
])
}')" | tee -a "$GITHUB_OUTPUT"
env:
search_result: ${{ steps.search.outputs.result }}

- name: Send message to Slack
id: send
if: steps.transform.outputs.result != null
uses: slackapi/slack-github-action@e28cf165c92ffef168d23c5c9000cffc8a25e117 # v1.24.0
with:
channel-id: topic-pi-referandmonitor
payload: ${{ steps.transform.outputs.result }}
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ internal class ReferAndMonitorIntegrationTest {
channelManager.getChannel(queueName).publishAndWait(notification)

verify(telemetryService).trackEvent(
"AppointmentNotFound",
"ReferAndMonitorFailureReport",
mapOf(
"crn" to "T140223",
"referralId" to "cb293dcb-c201-4743-aa9d-acb14c8a1ddd",
Expand All @@ -384,7 +384,8 @@ internal class ReferAndMonitorIntegrationTest {
"outcomeAttended" to "NO",
"outcomeNotify" to "true",
"reason" to "NSI terminated, likely a future appointment deleted",
"reasonDetail" to "NSI last updated by ReferAndMonitorAndDelius"
"reasonDetail" to "NSI last updated by ReferAndMonitorAndDelius",
"message" to "Appointment Not Found"
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class AppointmentNotFoundException(
val outcome: Outcome,
val reason: AppointmentNotFoundReason
) : UnprocessableException(
"AppointmentNotFound",
"Appointment Not Found",
mapOf(
"appointmentId" to appointmentId.toString(),
"deliusId" to deliusId.toString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class ReferralNotFoundException(
date: LocalDate,
reason: String
) : UnprocessableException(
"ReferralNotFound",
"Referral Not Found",
listOfNotNull(
"referralUrn" to referralUrn,
"crn" to crn,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package uk.gov.justice.digital.hmpps.messaging

import org.springframework.stereotype.Component
import uk.gov.justice.digital.hmpps.exception.NotFoundException
import uk.gov.justice.digital.hmpps.exception.IgnorableMessageException
import uk.gov.justice.digital.hmpps.integrations.delius.contact.ContactRepository
import uk.gov.justice.digital.hmpps.integrations.delius.contact.ContactTypeRepository
import uk.gov.justice.digital.hmpps.integrations.delius.contact.entity.Contact
Expand Down Expand Up @@ -34,7 +34,10 @@ class ActionPlanNotification(

fun notify(notification: ActionPlanNotification): EventProcessingResult {
val nsi = nsiRepository.findByPersonCrnAndExternalReference(notification.crn, notification.referral.urn)
?: throw NotFoundException("Unable to find referral for action plan notification ${notification.crn} => ${notification.referral.id}")
?: throw IgnorableMessageException(
"Unable to find referral for action plan notification",
mapOf("crn" to notification.crn, "referralId" to notification.referral.id)
)
contactRepository.findNotificationContact(
nsi.id,
ContactType.Code.CRSNOTE.value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import uk.gov.justice.digital.hmpps.converter.NotificationConverter
import uk.gov.justice.digital.hmpps.exception.UnprocessableException
import uk.gov.justice.digital.hmpps.message.HmppsDomainEvent
import uk.gov.justice.digital.hmpps.message.Notification
import uk.gov.justice.digital.hmpps.messaging.EventProcessingResult.Failure
import uk.gov.justice.digital.hmpps.messaging.EventProcessingResult.Rejected
import uk.gov.justice.digital.hmpps.messaging.EventProcessingResult.Success
import uk.gov.justice.digital.hmpps.messaging.EventProcessingResult.*
import uk.gov.justice.digital.hmpps.telemetry.TelemetryService

@Component
Expand Down Expand Up @@ -38,8 +36,8 @@ class ReferAndMonitorHandler(

is Rejected -> {
telemetryService.trackEvent(
res.exception.message!!,
notification.message.commonFields() + res.properties
"ReferAndMonitorFailureReport",
notification.message.commonFields() + res.properties + ("message" to res.exception.message!!)
)
}

Expand Down

0 comments on commit bb4c0d9

Please sign in to comment.