Skip to content

Commit

Permalink
logging
Browse files Browse the repository at this point in the history
  • Loading branch information
shalom938 committed Dec 18, 2024
1 parent f7476ab commit 846e27f
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 83 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import org.digma.intellij.plugin.ui.panels.DigmaResettablePanel
import org.digma.intellij.plugin.updates.ui.NewUIVersionAvailableEvent
import org.digma.intellij.plugin.updates.ui.UIVersioningService
import java.util.concurrent.TimeUnit
import java.util.concurrent.locks.ReentrantLock
import kotlin.concurrent.withLock
import kotlin.time.Duration
import kotlin.time.Duration.Companion.seconds

Expand All @@ -35,6 +37,8 @@ class UpdatesService(private val project: Project) : Disposable {

private val logger = Logger.getInstance(UpdatesService::class.java)

private val checkLock = ReentrantLock(true)

companion object {
@JvmStatic
fun getInstance(project: Project): UpdatesService {
Expand Down Expand Up @@ -143,40 +147,44 @@ class UpdatesService(private val project: Project) : Disposable {
//this method may throw exception, always catch and report
private fun checkForNewerVersions() {

Log.log(logger::trace, "checking for new versions")
val versionsResp: VersionResponse = AnalyticsService.getInstance(project).getVersions(buildVersionRequest())
Log.log(logger::debug, "got version response {}", versionsResp)
checkLock.withLock {

Log.log(logger::trace, "checking for new versions")
val versionsResp: VersionResponse = AnalyticsService.getInstance(project).getVersions(buildVersionRequest())
Log.log(logger::debug, "got version response {}", versionsResp)

if (versionsResp.errors.isNotEmpty()) {
val currErrors = versionsResp.errors.toList()
if (versionsResp.errors.isNotEmpty()) {
val currErrors = versionsResp.errors.toList()

if (currErrors != prevBackendErrorsList) {
currErrors.forEach {
ErrorReporter.getInstance().reportBackendError(project, "UpdatesService.checkForNewerVersions", it)
if (currErrors != prevBackendErrorsList) {
currErrors.forEach {
ErrorReporter.getInstance().reportBackendError(project, "UpdatesService.checkForNewerVersions", it)
}
}

prevBackendErrorsList = currErrors
return
}

prevBackendErrorsList = currErrors
return
}
stateBackendVersion = versionsResp.backend
statePluginVersion.latestVersion = versionsResp.plugin.latestVersion

//the panel is going to show the update button if shouldUpdatePlugin is true.
//when user clicks the button we will open the intellij plugins settings.
//sometimes the plugin list is not refreshed and user will not be able to update the plugin,
// so we refresh plugins metadata before showing the button. waiting maximum 10 seconds for
// the refresh to complete, and show the button anyway.
if (shouldUpdatePlugin()) {
//refreshPluginsMetadata returns a future that doesn't throw exception from get.
val future = refreshPluginsMetadata()
future.get(10, TimeUnit.SECONDS)
}

stateBackendVersion = versionsResp.backend
statePluginVersion.latestVersion = versionsResp.plugin.latestVersion

//the panel is going to show the update button if shouldUpdatePlugin is true.
//when user clicks the button we will open the intellij plugins settings.
//sometimes the plugin list is not refreshed and user will not be able to update the plugin,
// so we refresh plugins metadata before showing the button. waiting maximum 10 seconds for
// the refresh to complete, and show the button anyway.
if (shouldUpdatePlugin()) {
//refreshPluginsMetadata returns a future that doesn't throw exception from get.
val future = refreshPluginsMetadata()
future.get(10, TimeUnit.SECONDS)
EDT.ensureEDT {
affectedPanel?.reset()
}
}

EDT.ensureEDT {
affectedPanel?.reset()
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,14 @@ class UIVersioningService(val cs: CoroutineScope) : DisposableAdaptor {
if (latestDownloadedUiVersion != null) {
Log.log(
logger::info,
"updating ui to latest downloaded version {}", latestDownloadedUiVersion
"got latest downloaded ui version on startup {}, trying to update..", latestDownloadedUiVersion
)
val latestDownloadedUi = buildUiBundleLocalFile(latestDownloadedUiVersion)
if (latestDownloadedUi.exists()) {
Log.log(
logger::info,
"updating ui to latest downloaded version on startup {}", latestDownloadedUiVersion
)
deleteUiBundle(getCurrentUiVersion())
setCurrentUiVersion(latestDownloadedUiVersion)
setLatestDownloadedVersion(null)
Expand Down

This file was deleted.

This file was deleted.

0 comments on commit 846e27f

Please sign in to comment.