Skip to content

Commit

Permalink
Merge pull request #5 from vinted/feature/implement_timeout
Browse files Browse the repository at this point in the history
Add 30 second timeout
  • Loading branch information
oleg-vinted authored Jul 21, 2023
2 parents e043af1 + 34fb615 commit a290e37
Showing 1 changed file with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@ import org.jetbrains.plugins.ruby.ruby.lang.psi.references.RColonReference
import org.jetbrains.plugins.ruby.ruby.lang.psi.variables.RConstant
import java.nio.charset.Charset
import java.util.*
import java.util.concurrent.TimeUnit

private val violationPattern = Regex("^[^:]+:([0-9]+):([0-9]+)$")

private const val runTimeout: Long = 30
private val runTimeoutUnit = TimeUnit.SECONDS

internal class PackwerkAnnotator : ExternalAnnotator<PackwerkAnnotator.State, PackwerkAnnotator.Results>() {
internal class State(
var file: PsiFile,
Expand Down Expand Up @@ -68,6 +72,12 @@ internal class PackwerkAnnotator : ExternalAnnotator<PackwerkAnnotator.State, Pa
return null
}

if (!process.waitFor(runTimeout, runTimeoutUnit)) {
process.destroyForcibly().waitFor()
thisLogger().warn("Packwerk process timed out")
return null
}

val scanner = Scanner(process.inputStream)
val problems = ArrayList<Problem>()

Expand Down

0 comments on commit a290e37

Please sign in to comment.