-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CID-2143: Change code to finish run before start the full scan
- Loading branch information
1 parent
6ee9db1
commit 64f3e9a
Showing
6 changed files
with
79 additions
and
64 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
src/main/kotlin/net/leanix/vsm/githubbroker/connector/application/RunService.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,58 @@ | ||
package net.leanix.vsm.githubbroker.connector.application | ||
|
||
import net.leanix.vsm.githubbroker.connector.adapter.feign.FeignRunStatusProvider | ||
import net.leanix.vsm.githubbroker.connector.adapter.feign.data.RunState | ||
import net.leanix.vsm.githubbroker.connector.adapter.feign.data.UpdateRunStateRequest | ||
import net.leanix.vsm.githubbroker.connector.domain.Assignment | ||
import net.leanix.vsm.githubbroker.shared.Constants | ||
import net.leanix.vsm.githubbroker.shared.cache.AssignmentCache | ||
import org.slf4j.LoggerFactory | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class RunService( | ||
private val assignmentService: AssignmentService, | ||
private val runStatusProvider: FeignRunStatusProvider, | ||
) { | ||
|
||
private val logger = LoggerFactory.getLogger(RunService::class.java) | ||
|
||
fun getAssignments(): List<Assignment>? { | ||
kotlin.runCatching { | ||
finishRuns("Finish runs").let { | ||
AssignmentCache.deleteAll() | ||
val assignments = assignmentService.getAssignments() | ||
println(assignments.first().workspaceId) | ||
AssignmentCache.addAll(assignments) | ||
return assignments | ||
} | ||
}.onFailure { | ||
logger.error(it.message) | ||
logger.error("Failed to get initial state. No assignment found for this workspace id") | ||
} | ||
return null | ||
} | ||
|
||
fun finishRuns(message: String) { | ||
runCatching { | ||
if (AssignmentCache.getAll().isEmpty()) { | ||
logger.info("$message before receiving any assignment") | ||
} else { | ||
AssignmentCache.getAll().values.forEach { assignment -> | ||
runStatusProvider.updateRunStatus( | ||
assignment.runId.toString(), | ||
UpdateRunStateRequest( | ||
state = RunState.FINISHED, | ||
workspaceId = assignment.workspaceId.toString(), | ||
connector = Constants.GITHUB_ENTERPRISE_CONNECTOR, | ||
orgName = assignment.organizationName, | ||
message = message, | ||
), | ||
) | ||
} | ||
} | ||
}.onFailure { | ||
logger.error("Error finishing run: ", it) | ||
} | ||
} | ||
} |
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
26 changes: 4 additions & 22 deletions
26
src/main/kotlin/net/leanix/vsm/githubbroker/connector/runner/ShutdownService.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 |
---|---|---|
@@ -1,36 +1,18 @@ | ||
package net.leanix.vsm.githubbroker.connector.runner | ||
|
||
import jakarta.annotation.PreDestroy | ||
import net.leanix.vsm.githubbroker.connector.adapter.feign.FeignRunStatusProvider | ||
import net.leanix.vsm.githubbroker.connector.adapter.feign.data.RunState | ||
import net.leanix.vsm.githubbroker.connector.adapter.feign.data.UpdateRunStateRequest | ||
import net.leanix.vsm.githubbroker.shared.Constants.GITHUB_ENTERPRISE_CONNECTOR | ||
import net.leanix.vsm.githubbroker.shared.cache.AssignmentCache | ||
import net.leanix.vsm.githubbroker.connector.application.RunService | ||
import org.slf4j.LoggerFactory | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class ShutdownService(private val runStatusProvider: FeignRunStatusProvider) { | ||
class ShutdownService(private val runService: RunService) { | ||
|
||
private val logger = LoggerFactory.getLogger(ShutdownService::class.java) | ||
|
||
@PreDestroy | ||
fun onDestroy() { | ||
if (AssignmentCache.getAll().isEmpty()) { | ||
logger.info("Shutting down github broker before receiving any assignment") | ||
} else { | ||
AssignmentCache.getAll().values.forEach { assignment -> | ||
runStatusProvider.updateRunStatus( | ||
assignment.runId.toString(), | ||
UpdateRunStateRequest( | ||
state = RunState.FINISHED, | ||
workspaceId = assignment.workspaceId.toString(), | ||
connector = GITHUB_ENTERPRISE_CONNECTOR, | ||
orgName = assignment.organizationName, | ||
message = "Gracefully stopped github enterprise" | ||
) | ||
) | ||
} | ||
} | ||
logger.info("Shutting down github broker") | ||
runService.finishRuns("Gracefully stopped github enterprise") | ||
} | ||
} |
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