Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.leanix.githubagent.runners
package net.leanix.githubagent.listener

import net.leanix.githubagent.handler.BrokerStompSessionHandler
import net.leanix.githubagent.services.CachingService
Expand All @@ -9,26 +9,26 @@ import net.leanix.githubagent.services.SyncLogService
import net.leanix.githubagent.services.WebSocketService
import net.leanix.githubagent.shared.APP_NAME_TOPIC
import org.slf4j.LoggerFactory
import org.springframework.boot.ApplicationArguments
import org.springframework.boot.ApplicationRunner
import org.springframework.boot.context.event.ApplicationReadyEvent
import org.springframework.context.ApplicationListener
import org.springframework.context.annotation.Profile
import org.springframework.stereotype.Component

@Component
@Profile("!test")
class PostStartupRunner(
class ApplicationReadyListener(
private val githubAuthenticationService: GitHubAuthenticationService,
private val webSocketService: WebSocketService,
private val gitHubScanningService: GitHubScanningService,
private val gitHubEnterpriseService: GitHubEnterpriseService,
private val cachingService: CachingService,
private val brokerStompSessionHandler: BrokerStompSessionHandler,
private val syncLogService: SyncLogService
) : ApplicationRunner {
) : ApplicationListener<ApplicationReadyEvent> {

private val logger = LoggerFactory.getLogger(PostStartupRunner::class.java)
private val logger = LoggerFactory.getLogger(this::class.java)

override fun run(args: ApplicationArguments?) {
override fun onApplicationEvent(event: ApplicationReadyEvent) {
webSocketService.initSession()
if (!brokerStompSessionHandler.isConnected()) {
logger.error("Stopping the application as the WebSocket connection could not be established.")
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ resilience4j.retry:
maxAttempts: 5
enable-exponential-backoff: true
exponential-backoff-multiplier: 2
waitDuration: 1000
waitDuration: 5s
logging:
level:
org.springframework.web.socket.handler: DEBUG
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.leanix.githubagent.runners
package net.leanix.githubagent.listener

import io.mockk.every
import io.mockk.mockk
Expand All @@ -15,14 +15,14 @@ import net.leanix.githubagent.shared.APP_NAME_TOPIC
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test

class PostStartupRunnerTest {
class ApplicationReadyListenerTest {

private lateinit var githubAuthenticationService: GitHubAuthenticationService
private lateinit var webSocketService: WebSocketService
private lateinit var gitHubScanningService: GitHubScanningService
private lateinit var gitHubEnterpriseService: GitHubEnterpriseService
private lateinit var cachingService: CachingService
private lateinit var postStartupRunner: PostStartupRunner
private lateinit var applicationListener: ApplicationReadyListener
private lateinit var brokerStompSessionHandler: BrokerStompSessionHandler
private lateinit var syncLogService: SyncLogService

Expand All @@ -36,7 +36,7 @@ class PostStartupRunnerTest {
brokerStompSessionHandler = mockk()
syncLogService = mockk()

postStartupRunner = PostStartupRunner(
applicationListener = ApplicationReadyListener(
githubAuthenticationService,
webSocketService,
gitHubScanningService,
Expand Down Expand Up @@ -67,7 +67,7 @@ class PostStartupRunnerTest {
gitHubAppName, mapOf(), listOf()
)

postStartupRunner.run(mockk())
applicationListener.onApplicationEvent(mockk())

verify { webSocketService.sendMessage(APP_NAME_TOPIC, gitHubAppName) }
verify { syncLogService.sendFullScanStart(any()) }
Expand Down
Loading