Skip to content

Commit 8c1a262

Browse files
committed
Merge pull request #5 from codacy/enterprise
Docker timeout on engine scala seed.
2 parents 11164c3 + 9333d18 commit 8c1a262

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

build.sbt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ scalacOptions := Seq("-deprecation", "-feature", "-unchecked", "-Ywarn-adapted-a
1313
resolvers += "Bintray Typesafe Repo" at "http://dl.bintray.com/typesafe/maven-releases/"
1414

1515
libraryDependencies ++= Seq(
16-
"com.typesafe.play" %% "play-json" % "2.3.10",
17-
"org.scalatest" %% "scalatest" % "2.2.4" % "test"
16+
"com.typesafe.play" %% "play-json" % "2.3.10",
17+
"org.scalatest" %% "scalatest" % "2.2.4" % "test",
18+
"com.typesafe.akka" %% "akka-actor" % "2.3.14"
1819
)
1920

2021
organizationName := "Codacy"

src/main/scala/codacy/dockerApi/DockerEngine.scala

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,39 @@
11
package codacy.dockerApi
22

3+
import akka.actor.ActorSystem
34
import codacy.dockerApi.DockerEnvironment._
45
import play.api.libs.json.{Json, Writes}
56

6-
import scala.util.{Failure, Success}
7+
import scala.concurrent.ExecutionContext
8+
import scala.concurrent.duration._
9+
import scala.util.{Failure, Success, Try}
710

811
abstract class DockerEngine(Tool: Tool) {
912

13+
lazy val sys = ActorSystem("timeoutSystem")
14+
15+
def initTimeout(duration: FiniteDuration) = {
16+
implicit val ct: ExecutionContext = sys.dispatcher
17+
sys.scheduler.scheduleOnce(duration){
18+
Runtime.getRuntime().halt(2)
19+
}
20+
}
21+
22+
lazy val timeout = Option(System.getProperty("timeout")).flatMap{ case rawDuration =>
23+
Try(Duration(rawDuration)).toOption.collect{ case d:FiniteDuration => d }
24+
}.getOrElse(30.minutes)
25+
26+
lazy val isDebug = Option(System.getProperty("debug")).flatMap{ case rawDebug =>
27+
Try(rawDebug.toBoolean).toOption
28+
}.getOrElse(false)
29+
30+
def log(message:String):Unit = if(isDebug){
31+
Console.err.print(s"[DockerEngine] $message")
32+
}
33+
1034
def main(args: Array[String]): Unit = {
35+
initTimeout(timeout)
36+
1137
spec.flatMap { implicit spec =>
1238
config.flatMap { case maybeConfig =>
1339
//search for our config
@@ -19,6 +45,7 @@ abstract class DockerEngine(Tool: Tool) {
1945
sourcePath.resolve(path.value)
2046
}))
2147

48+
log("tool started")
2249
Tool(
2350
path = sourcePath,
2451
conf = maybePatterns,
@@ -27,6 +54,7 @@ abstract class DockerEngine(Tool: Tool) {
2754
}
2855
} match {
2956
case Success(results) =>
57+
log("receiving results")
3058
results.foreach {
3159
case issue: Issue =>
3260
val relativeIssue = issue.copy(filename = SourcePath(relativize(issue.filename.value)))
@@ -35,7 +63,7 @@ abstract class DockerEngine(Tool: Tool) {
3563
val relativeIssue = error.copy(filename = SourcePath(relativize(error.filename.value)))
3664
logResult(relativeIssue)
3765
}
38-
66+
log("tool finished")
3967
case Failure(error) =>
4068
error.printStackTrace(Console.err)
4169
System.exit(1)

0 commit comments

Comments
 (0)