Skip to content

Commit

Permalink
fix:jobs reloading while workflow is running
Browse files Browse the repository at this point in the history
  • Loading branch information
cunla committed Apr 24, 2024
1 parent fc16563 commit 38a3ddd
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ class WorkflowRunSelectionContext internal constructor(
}

fun resetAllData() {
cache.invalidateAll()
runsListLoader.reset()
runsListLoader.loadMore(true)
jobDataProviderLoadModel.value = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,26 @@ import com.dsoftware.ghmanager.api.GhApiRequestExecutor
import com.dsoftware.ghmanager.api.GithubApi
import com.dsoftware.ghmanager.api.model.Job
import com.dsoftware.ghmanager.api.model.WorkflowRunJobs
import com.intellij.collaboration.async.CompletableFutureUtil.submitIOTask
import com.intellij.collaboration.util.ProgressIndicatorsProvider
import com.intellij.openapi.Disposable
import com.intellij.openapi.diagnostic.thisLogger
import com.intellij.openapi.progress.ProgressManager
import com.intellij.util.EventDispatcher
import org.jetbrains.plugins.github.api.GithubApiRequest
import org.jetbrains.plugins.github.exceptions.GithubStatusCodeException
import org.jetbrains.plugins.github.util.LazyCancellableBackgroundProcessValue
import java.io.IOException
import java.util.EventListener
import java.util.concurrent.CompletableFuture
import kotlin.properties.ReadOnlyProperty

open class DataProvider<T>(
private val requestExecutor: GhApiRequestExecutor,
private val githubApiRequest: GithubApiRequest<T>,
) {
private val runChangesEventDispatcher = EventDispatcher.create(DataProviderChangeListener::class.java)

val processValue = ProgressManager.getInstance()
.submitIOTask(ProgressIndicatorsProvider(), true) {
private val processBackgroundProcess: LazyCancellableBackgroundProcessValue<T> =
LazyCancellableBackgroundProcessValue.create(ProgressManager.getInstance()) {
try {
LOG.info("Executing ${githubApiRequest.url}")
val request = githubApiRequest
Expand All @@ -36,12 +37,17 @@ open class DataProvider<T>(
throw ioe
}
}
val processValue by backgroundProcessValue(processBackgroundProcess)

private fun <T> backgroundProcessValue(backingValue: LazyCancellableBackgroundProcessValue<T>)
: ReadOnlyProperty<Any?, CompletableFuture<T>> =
ReadOnlyProperty { _, _ -> backingValue.value }

fun url(): String = githubApiRequest.url

fun reload() {
LOG.debug("Reloading data for ${githubApiRequest.url}")
processValue.cancel(true)
processBackgroundProcess.drop()
runChangesEventDispatcher.multicaster.changed()
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<!-- PSI -->
<postStartupActivity implementation="com.dsoftware.ghmanager.psi.ProjectStartup"/>
<annotator language="yaml"
implementationClass="com.dsoftware.ghmanager.psi.HighlightAnnotator"/>
implementationClass="com.dsoftware.ghmanager.psi.OutdatedVersionAnnotator"/>
</extensions>
<actions>
<action id="ShowGithubSettings" class="com.dsoftware.ghmanager.actions.ShowGithubSettingsAction"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.dsoftware.ghmanager.api

import com.dsoftware.ghmanager.api.model.WorkflowRunJobs
import com.dsoftware.ghmanager.createJob
import com.dsoftware.ghmanager.TestTools.createJob
import com.dsoftware.ghmanager.withStep
import org.jetbrains.plugins.github.api.GithubApiContentHelper
import org.junit.jupiter.api.Assertions.assertTrue
Expand Down

0 comments on commit 38a3ddd

Please sign in to comment.