From 80618c8037e83402833060e4463432db5ca4f7f3 Mon Sep 17 00:00:00 2001 From: Travis Woodward <104013113+Travis-Softwire@users.noreply.github.com> Date: Thu, 30 Oct 2025 11:44:26 +0000 Subject: [PATCH 1/4] PRSD-1604: Creates example application runner for scheduled tasks --- .../ExampleScheduledTaskApplicationRunner.kt | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/main/kotlin/uk/gov/communities/prsdb/webapp/application/ExampleScheduledTaskApplicationRunner.kt diff --git a/src/main/kotlin/uk/gov/communities/prsdb/webapp/application/ExampleScheduledTaskApplicationRunner.kt b/src/main/kotlin/uk/gov/communities/prsdb/webapp/application/ExampleScheduledTaskApplicationRunner.kt new file mode 100644 index 0000000000..bf92f59ec9 --- /dev/null +++ b/src/main/kotlin/uk/gov/communities/prsdb/webapp/application/ExampleScheduledTaskApplicationRunner.kt @@ -0,0 +1,25 @@ +package uk.gov.communities.prsdb.webapp.application + +import org.springframework.boot.ApplicationArguments +import org.springframework.boot.ApplicationRunner +import org.springframework.boot.SpringApplication +import org.springframework.context.ApplicationContext +import org.springframework.context.annotation.Profile +import org.springframework.stereotype.Component +import kotlin.system.exitProcess + +@Component +@Profile("web-server-deactivated & example-scheduled-task") +class ExampleScheduledTaskApplicationRunner( + private val context: ApplicationContext, +) : ApplicationRunner { + override fun run(args: ApplicationArguments?) { + println("Executing example scheduled task") + + val code = + SpringApplication.exit(context, { 0 }).also { + println("Scheduled task executed. Application will exit now.") + } + exitProcess(code) + } +} From f98898bac1c244d39f95f7eb7d370a80203950bb Mon Sep 17 00:00:00 2001 From: Travis Woodward <104013113+Travis-Softwire@users.noreply.github.com> Date: Mon, 3 Nov 2025 12:36:11 +0000 Subject: [PATCH 2/4] PRSD-1604: Adds default scheduled task handler --- .../DefaultScheduledTaskApplicationRunner.kt | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/main/kotlin/uk/gov/communities/prsdb/webapp/application/DefaultScheduledTaskApplicationRunner.kt diff --git a/src/main/kotlin/uk/gov/communities/prsdb/webapp/application/DefaultScheduledTaskApplicationRunner.kt b/src/main/kotlin/uk/gov/communities/prsdb/webapp/application/DefaultScheduledTaskApplicationRunner.kt new file mode 100644 index 0000000000..3fe6c67ed9 --- /dev/null +++ b/src/main/kotlin/uk/gov/communities/prsdb/webapp/application/DefaultScheduledTaskApplicationRunner.kt @@ -0,0 +1,24 @@ +package uk.gov.communities.prsdb.webapp.application + +import org.springframework.boot.ApplicationRunner +import org.springframework.context.ApplicationContext +import org.springframework.context.annotation.Profile +import org.springframework.core.Ordered +import org.springframework.core.annotation.Order +import org.springframework.stereotype.Component +import kotlin.system.exitProcess + +@Component +@Profile("web-server-deactivated") +@Order(Ordered.LOWEST_PRECEDENCE) +class DefaultScheduledTaskApplicationRunner( + private val context: ApplicationContext, +) : ApplicationRunner { + override fun run(args: org.springframework.boot.ApplicationArguments?) { + println("The application was not configured for this scheduled task. Application will exit now.") + + val code = + org.springframework.boot.SpringApplication.exit(context, { 0 }) + exitProcess(code) + } +} From 8bab26a479e9b1525411d410e8aea22ddeb9ac0a Mon Sep 17 00:00:00 2001 From: Travis Woodward <104013113+Travis-Softwire@users.noreply.github.com> Date: Mon, 3 Nov 2025 16:19:14 +0000 Subject: [PATCH 3/4] PRSD-1604: Remove accidental qualification from class names --- .../application/DefaultScheduledTaskApplicationRunner.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/uk/gov/communities/prsdb/webapp/application/DefaultScheduledTaskApplicationRunner.kt b/src/main/kotlin/uk/gov/communities/prsdb/webapp/application/DefaultScheduledTaskApplicationRunner.kt index 3fe6c67ed9..22dccb2f05 100644 --- a/src/main/kotlin/uk/gov/communities/prsdb/webapp/application/DefaultScheduledTaskApplicationRunner.kt +++ b/src/main/kotlin/uk/gov/communities/prsdb/webapp/application/DefaultScheduledTaskApplicationRunner.kt @@ -1,6 +1,8 @@ package uk.gov.communities.prsdb.webapp.application +import org.springframework.boot.ApplicationArguments import org.springframework.boot.ApplicationRunner +import org.springframework.boot.SpringApplication import org.springframework.context.ApplicationContext import org.springframework.context.annotation.Profile import org.springframework.core.Ordered @@ -14,11 +16,11 @@ import kotlin.system.exitProcess class DefaultScheduledTaskApplicationRunner( private val context: ApplicationContext, ) : ApplicationRunner { - override fun run(args: org.springframework.boot.ApplicationArguments?) { + override fun run(args: ApplicationArguments?) { println("The application was not configured for this scheduled task. Application will exit now.") val code = - org.springframework.boot.SpringApplication.exit(context, { 0 }) + SpringApplication.exit(context, { 0 }) exitProcess(code) } } From d896031c602b138a61a14757bc51435b9b09a59f Mon Sep 17 00:00:00 2001 From: Travis Woodward <104013113+Travis-Softwire@users.noreply.github.com> Date: Wed, 5 Nov 2025 07:47:02 +0000 Subject: [PATCH 4/4] PRSD-1604: Switch to using profiles to identify scheduled tasks --- .../webapp/application/DefaultScheduledTaskApplicationRunner.kt | 2 +- .../webapp/application/ExampleScheduledTaskApplicationRunner.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/uk/gov/communities/prsdb/webapp/application/DefaultScheduledTaskApplicationRunner.kt b/src/main/kotlin/uk/gov/communities/prsdb/webapp/application/DefaultScheduledTaskApplicationRunner.kt index 22dccb2f05..3dab78771a 100644 --- a/src/main/kotlin/uk/gov/communities/prsdb/webapp/application/DefaultScheduledTaskApplicationRunner.kt +++ b/src/main/kotlin/uk/gov/communities/prsdb/webapp/application/DefaultScheduledTaskApplicationRunner.kt @@ -11,7 +11,7 @@ import org.springframework.stereotype.Component import kotlin.system.exitProcess @Component -@Profile("web-server-deactivated") +@Profile("web-server-deactivated & scheduled-task") @Order(Ordered.LOWEST_PRECEDENCE) class DefaultScheduledTaskApplicationRunner( private val context: ApplicationContext, diff --git a/src/main/kotlin/uk/gov/communities/prsdb/webapp/application/ExampleScheduledTaskApplicationRunner.kt b/src/main/kotlin/uk/gov/communities/prsdb/webapp/application/ExampleScheduledTaskApplicationRunner.kt index bf92f59ec9..50894f5c51 100644 --- a/src/main/kotlin/uk/gov/communities/prsdb/webapp/application/ExampleScheduledTaskApplicationRunner.kt +++ b/src/main/kotlin/uk/gov/communities/prsdb/webapp/application/ExampleScheduledTaskApplicationRunner.kt @@ -9,7 +9,7 @@ import org.springframework.stereotype.Component import kotlin.system.exitProcess @Component -@Profile("web-server-deactivated & example-scheduled-task") +@Profile("web-server-deactivated & scheduled-task & example-scheduled-task") class ExampleScheduledTaskApplicationRunner( private val context: ApplicationContext, ) : ApplicationRunner {