Skip to content

Commit

Permalink
chore: use jetbrains cli platform (#11)
Browse files Browse the repository at this point in the history
add backoff on the the running so that multiple runs at a time can't
happen and only queue one at a time.
  • Loading branch information
Owen authored Jul 4, 2024
1 parent 96d5eaa commit 26ce56a
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 6 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@

## [Unreleased]

## [1.1.1] - 2024-07-04
### Fixed
- Limit subsequent runs to one queued run, this handles large scale saves and button mashing

### Changed
- Set the platform identifier to jetbrains

## [1.1.0] - 2024-07-02
### Added
- Support for config files
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
pluginGroup = io.infracost.plugins
pluginName = Infracost
pluginRepositoryUrl = https://github.com/infracost/jetbrains-infracost
pluginVersion = 1.1.0
pluginVersion = 1.1.1

pluginSinceBuild = 232
pluginUntilBuild = 242.*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ object ResultProcessor {
)
return
} finally {
resultFile?.deleteOnExit()
resultFile?.delete()
}

// redraw the explorer with the updated content
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import io.infracost.plugins.infracost.actions.tasks.InfracostBackgroundRunTask
import io.infracost.plugins.infracost.ui.notify.InfracostNotificationGroup
import java.io.File
import java.io.IOException
import java.util.concurrent.atomic.AtomicBoolean
import java.util.concurrent.atomic.AtomicReference
import javax.swing.SwingUtilities

/** RunInfracostAction executes infracost then calls update results */
Expand All @@ -36,6 +38,8 @@ class RunInfracostAction : AnAction() {
}

companion object {
private val running = AtomicBoolean(false)
private val next = AtomicReference<InfracostBackgroundRunTask>()

fun runInfracost(project: Project) {
var resultFile: File? = null
Expand All @@ -45,11 +49,28 @@ class RunInfracostAction : AnAction() {
InfracostNotificationGroup.notifyError(project, ex.localizedMessage)
}

// mark the file for deletion on exit
resultFile?.deleteOnExit()

val runner =
InfracostBackgroundRunTask(project, resultFile!!) { proj: Project, f: File? ->
ResultProcessor.updateResults(proj, f)
running.set(false)
val queued = next.getAndSet(null)
if (queued != null) {
running.set(true)
ProgressManager.getInstance().run(queued)
}
}

if (running.get()) {
// If a run is already in progress, queue the next run
next.set(runner)
return
}

if (SwingUtilities.isEventDispatchThread()) {
running.set(true)
ProgressManager.getInstance().run(runner)
} else {
ApplicationManager.getApplication().invokeLater(runner)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ internal class InfracostAuthRunTask(
"INFRACOST_SKIP_UPDATE_CHECK" to "true",
"INFRACOST_GRAPH_EVALUATOR" to "true",
"INFRACOST_NO_COLOR" to "true",
"INFRACOST_CLI_PLATFORM" to "vscode",
"INFRACOST_CLI_PLATFORM" to "jetbrains",
)
)
ApplicationManager.getApplication().executeOnPooledThread {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ internal class InfracostBackgroundRunTask(
GeneralCommandLine(commandParts)
.withEnvironment(
mapOf(
"INFRACOST_CLI_PLATFORM" to "jetbrains",
"INFRACOST_SKIP_UPDATE_CHECK" to "true",
"INFRACOST_GRAPH_EVALUATOR" to "true",
"INFRACOST_NO_COLOR" to "true"
Expand All @@ -76,9 +77,6 @@ internal class InfracostBackgroundRunTask(
ScriptRunnerUtil.getProcessOutput(
handler, ScriptRunnerUtil.STDOUT_OR_STDERR_OUTPUT_KEY_FILTER, 100000000
)
InfracostNotificationGroup.notifyInformation(
project, "infracost run completed, updating results"
)
SwingUtilities.invokeLater { callback.accept(this.project, this.resultFile) }
} catch (e: ExecutionException) {
InfracostNotificationGroup.notifyError(project, e.localizedMessage)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ internal class InfracostCheckAuthRunTask(
GeneralCommandLine(commandParams)
.withEnvironment(
mapOf(
"INFRACOST_CLI_PLATFORM" to "jetbrains",
"INFRACOST_SKIP_UPDATE_CHECK" to "true",
"INFRACOST_GRAPH_EVALUATOR" to "true",
"INFRACOST_NO_COLOR" to "true"
Expand Down

0 comments on commit 26ce56a

Please sign in to comment.