Skip to content

Commit 936fcca

Browse files
PRSD-1604: Creates example application runner for scheduled tasks (#838)
1 parent 948a344 commit 936fcca

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package uk.gov.communities.prsdb.webapp.application
2+
3+
import org.springframework.boot.ApplicationArguments
4+
import org.springframework.boot.ApplicationRunner
5+
import org.springframework.boot.SpringApplication
6+
import org.springframework.context.ApplicationContext
7+
import org.springframework.context.annotation.Profile
8+
import org.springframework.core.Ordered
9+
import org.springframework.core.annotation.Order
10+
import org.springframework.stereotype.Component
11+
import kotlin.system.exitProcess
12+
13+
@Component
14+
@Profile("web-server-deactivated & scheduled-task")
15+
@Order(Ordered.LOWEST_PRECEDENCE)
16+
class DefaultScheduledTaskApplicationRunner(
17+
private val context: ApplicationContext,
18+
) : ApplicationRunner {
19+
override fun run(args: ApplicationArguments?) {
20+
println("The application was not configured for this scheduled task. Application will exit now.")
21+
22+
val code =
23+
SpringApplication.exit(context, { 0 })
24+
exitProcess(code)
25+
}
26+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package uk.gov.communities.prsdb.webapp.application
2+
3+
import org.springframework.boot.ApplicationArguments
4+
import org.springframework.boot.ApplicationRunner
5+
import org.springframework.boot.SpringApplication
6+
import org.springframework.context.ApplicationContext
7+
import org.springframework.context.annotation.Profile
8+
import org.springframework.stereotype.Component
9+
import kotlin.system.exitProcess
10+
11+
@Component
12+
@Profile("web-server-deactivated & scheduled-task & example-scheduled-task")
13+
class ExampleScheduledTaskApplicationRunner(
14+
private val context: ApplicationContext,
15+
) : ApplicationRunner {
16+
override fun run(args: ApplicationArguments?) {
17+
println("Executing example scheduled task")
18+
19+
val code =
20+
SpringApplication.exit(context, { 0 }).also {
21+
println("Scheduled task executed. Application will exit now.")
22+
}
23+
exitProcess(code)
24+
}
25+
}

0 commit comments

Comments
 (0)