generated from ministryofjustice/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
c99a2e9
commit 691f051
Showing
12 changed files
with
200 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...tment-reminders-and-delius/deploy/templates/unpaid-work-appointment-reminders-cronjob.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
apiVersion: batch/v1 | ||
kind: CronJob | ||
metadata: | ||
name: unpaid-work-appointment-reminders | ||
spec: | ||
schedule: {{ index .Values "jobs" "unpaid-work-appointment-reminders" "schedule" }} | ||
concurrencyPolicy: Forbid | ||
failedJobsHistoryLimit: 1 | ||
successfulJobsHistoryLimit: 1 | ||
jobTemplate: | ||
spec: | ||
template: | ||
spec: | ||
serviceAccountName: appointment-reminders-and-delius | ||
containers: | ||
- name: update-custody-key-dates | ||
image: "ghcr.io/ministryofjustice/hmpps-probation-integration-services/appointment-reminders-and-delius:{{ .Values.version }}" | ||
securityContext: | ||
capabilities: | ||
drop: | ||
- ALL | ||
runAsNonRoot: true | ||
allowPrivilegeEscalation: false | ||
seccompProfile: | ||
type: RuntimeDefault | ||
env: | ||
{{- range $secret, $envs := index .Values "generic-service" "namespace_secrets" }} | ||
{{- range $key, $val := $envs }} | ||
- name: {{ $key }} | ||
valueFrom: | ||
secretKeyRef: | ||
key: {{ trimSuffix "?" $val }} | ||
name: {{ $secret }}{{ if hasSuffix "?" $val }} | ||
optional: true{{ end }} {{- end }} | ||
{{- end }} | ||
{{- range $key, $val := index .Values "generic-service" "env" }} | ||
- name: {{ $key }} | ||
value: "{{ $val }}" | ||
{{- end }} | ||
- name: MESSAGING_CONSUMER_ENABLED | ||
value: "false" | ||
- name: JOBS_UNPAID-WORK-APPOINTMENT-REMINDERS_ENABLED | ||
value: "true" | ||
- name: JOBS_UNPAID-WORK-APPOINTMENT-REMINDERS_PROVIDER | ||
value: "N56" | ||
- name: JOBS_UNPAID-WORK-APPOINTMENT-REMINDERS_DRY-RUN | ||
value: "{{ index .Values "jobs" "unpaid-work-appointment-reminders" "dry-run" }}" | ||
restartPolicy: Never |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
...nd-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/config/NotificationClientConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package uk.gov.justice.digital.hmpps.config | ||
|
||
import org.springframework.beans.factory.annotation.Value | ||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
import uk.gov.service.notify.NotificationClient | ||
|
||
@Configuration | ||
class NotificationClientConfig { | ||
@Bean | ||
fun notificationClient(@Value("\${govuk-notify.api-key}") apiKey: String) = NotificationClient(apiKey) | ||
} |
27 changes: 27 additions & 0 deletions
27
...delius/src/main/kotlin/uk/gov/justice/digital/hmpps/cronjob/UpwAppointmentRemindersJob.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package uk.gov.justice.digital.hmpps.cronjob | ||
|
||
import org.springframework.beans.factory.annotation.Value | ||
import org.springframework.boot.SpringApplication.exit | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty | ||
import org.springframework.boot.context.event.ApplicationStartedEvent | ||
import org.springframework.context.ApplicationContext | ||
import org.springframework.context.ApplicationListener | ||
import org.springframework.stereotype.Component | ||
import uk.gov.justice.digital.hmpps.service.UnpaidWorkAppointmentsService | ||
import kotlin.system.exitProcess | ||
|
||
@Component | ||
@ConditionalOnProperty("jobs.unpaid-work-appointment-reminders.enabled") | ||
class UpwAppointmentRemindersJob( | ||
@Value("\${jobs.unpaid-work-appointment-reminders.provider}") | ||
private val providerCode: String, | ||
@Value("\${jobs.unpaid-work-appointment-reminders.dry-run:false}") | ||
private val dryRun: Boolean, | ||
private val service: UnpaidWorkAppointmentsService, | ||
private val applicationContext: ApplicationContext, | ||
) : ApplicationListener<ApplicationStartedEvent> { | ||
override fun onApplicationEvent(applicationStartedEvent: ApplicationStartedEvent) { | ||
service.sendUnpaidWorkAppointmentReminders(providerCode, dryRun) | ||
exitProcess(exit(applicationContext, { 0 })) | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...ius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/UnpaidWorkAppointmentsService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package uk.gov.justice.digital.hmpps.service | ||
|
||
import org.springframework.beans.factory.annotation.Value | ||
import org.springframework.stereotype.Service | ||
import uk.gov.justice.digital.hmpps.repository.UpwAppointmentRepository | ||
import uk.gov.justice.digital.hmpps.telemetry.TelemetryService | ||
import uk.gov.service.notify.NotificationClient | ||
import java.time.LocalDate | ||
|
||
@Service | ||
class UnpaidWorkAppointmentsService( | ||
private val upwAppointmentRepository: UpwAppointmentRepository, | ||
private val notificationClient: NotificationClient, | ||
private val telemetryService: TelemetryService, | ||
@Value("\${govuk-notify.templates.upw-appointment-reminder}") private val templateId: String, | ||
) { | ||
fun sendUnpaidWorkAppointmentReminders(providerCode: String, dryRun: Boolean = false) { | ||
upwAppointmentRepository.getUnpaidWorkAppointments(LocalDate.now().plusDays(2), providerCode) | ||
.forEach { | ||
notificationClient.sendSms( | ||
templateId, | ||
it.mobileNumber, | ||
mapOf("firstName" to it.firstName, "date" to it.appointmentDate), | ||
it.upwAppointmentIds | ||
) | ||
telemetryService.trackEvent( | ||
"SentUnpaidWorkAppointmentReminder", | ||
mapOf("crn" to it.crn, "upwAppointmentIds" to it.upwAppointmentIds) | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters