Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add response to ComponentsRegistryService.checkCacheActualityAndClean #21

Merged
merged 1 commit into from
Jun 10, 2024
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
Expand Up @@ -12,6 +12,7 @@ import org.octopusden.octopus.jira.model.VCSSettings
import org.octopusden.octopus.releng.dto.ComponentVersion
import org.octopusden.octopus.releng.dto.JiraComponentVersion
import java.util.Optional
import org.octopusden.octopus.jira.model.UpdateCacheResult
import org.octopusden.octopus.releng.JiraComponentVersionFormatter
import org.octopusden.releng.versions.VersionNames

Expand Down Expand Up @@ -55,7 +56,7 @@ interface ComponentRegistryService {

fun getDetailedComponentVersions(component: String, versions: Set<String>): DetailedComponentVersions

fun checkCacheActualityAndClean(forceClean: Boolean = false)
fun checkCacheActualityAndClean(forceClean: Boolean = false): UpdateCacheResult

fun getVersionNames(): VersionNames

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import com.atlassian.cache.CacheManager
import com.atlassian.jira.project.Project
import com.atlassian.jira.project.version.Version
import feign.FeignException
import java.util.Date
import java.util.Optional
import java.util.SortedSet
import org.octopusden.octopus.components.registry.client.ComponentsRegistryServiceClient
Expand Down Expand Up @@ -41,6 +40,7 @@ import org.octopusden.releng.versions.VersionNames
import org.slf4j.LoggerFactory
import javax.inject.Inject
import javax.inject.Named
import org.octopusden.octopus.jira.model.UpdateCacheResult

@Named
class ComponentRegistryServiceImpl @Inject constructor(
Expand All @@ -52,7 +52,7 @@ class ComponentRegistryServiceImpl @Inject constructor(

private val jiraComponentVersionFormatter = createJiraComponentVersionFormatter()

private var fixedRemoteDate: Date = Date(0L)
private var fixedRemoteStatus: Any = "initial status"

private val allComponentsCache = cacheManager.getCache(CacheId.ALL_COMPONENTS.id()) { _: Unit ->
client.getAllComponents().components.map { it.toModel() }
Expand Down Expand Up @@ -283,19 +283,20 @@ class ComponentRegistryServiceImpl @Inject constructor(
return detailedComponentVersionsCache.get(DetailedComponentVersionsCacheRequest(component, versions.toSortedSet()))!!
}

override fun checkCacheActualityAndClean(forceClean: Boolean) {
val remoteDate = client.getServiceStatus().cacheUpdatedAt
if (forceClean || this.fixedRemoteDate != remoteDate) {
log.info("Cleaning CR cache force=$forceClean $fixedRemoteDate != $remoteDate")
CacheId.values()
.forEach {
cacheManager.getManagedCache(it.id())
?.clear()
}
this.fixedRemoteDate = remoteDate
override fun checkCacheActualityAndClean(forceClean: Boolean): UpdateCacheResult {
val serviceStatus = client.getServiceStatus()
val remoteStatus = serviceStatus.versionControlRevision ?: serviceStatus.cacheUpdatedAt

val fixedRemoteStatus = this.fixedRemoteStatus

val message = if (forceClean || fixedRemoteStatus != remoteStatus) {
CacheId.values().forEach { cacheId -> cacheManager.getManagedCache(cacheId.id())?.clear() }
this.fixedRemoteStatus = remoteStatus
"Cleaned CR cache"
} else {
log.debug("Skip clean CR cache force=$forceClean fixedRemoteDate=$fixedRemoteDate remoteDate=$remoteDate")
"Skip clean CR cache"
}
return UpdateCacheResult("$message force='$forceClean', fixedRemoteStatus='$fixedRemoteStatus', remoteStatus='$remoteStatus'")
}

private fun <T> clearResponse(function: () -> T): T? {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package org.octopusden.octopus.jira.model

data class UpdateCacheResult(val message: String)
Loading