Skip to content

Commit

Permalink
implement worker
Browse files Browse the repository at this point in the history
This is a beginning of persistent worker idea,
which is intended to offload tests.
  • Loading branch information
eed3si9n committed Sep 30, 2024
1 parent 1ceef86 commit 8b4876d
Show file tree
Hide file tree
Showing 15 changed files with 505 additions and 2 deletions.
16 changes: 16 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,22 @@ lazy val testAgentProj = (project in file("testing") / "agent")
mimaSettings,
)

lazy val workerProj = (project in file("worker"))
.dependsOn(protocolProj, runProj, utilLogging, exampleWorkProj % Test)
.settings(
testedBaseSettings,
run / fork := false,
Test / fork := true,
Test / classLoaderLayeringStrategy := ClassLoaderLayeringStrategy.Flat,
)

lazy val exampleWorkProj = (project in file("internal") / "example-work")
.settings(
minimalSettings,
name := "example work",
publish / skip := true,
)

// Basic task engine
lazy val taskProj = (project in file("tasks"))
.dependsOn(collectionProj, utilControl)
Expand Down
5 changes: 5 additions & 0 deletions internal/example-work/src/main/scala/Hello.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package example

@main def main(args: String*): Unit =
if args.toList == List("boom") then sys.error("boom")
else println(s"${args.mkString}")

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions protocol/src/main/contraband/worker.contra
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package sbt.internal.worker
@target(Scala)
@codecPackage("sbt.internal.worker.codec")
@fullCodec("JsonProtocol")

type HashedPath {
path: String!,
digest: String!
}

type GeneralParams {
main_class: String!,
args: [String],
classpath: [sbt.internal.worker.HashedPath],
}

type ConsoleNotification {
ref: String!
stdout: String,
stderr: String,
}
18 changes: 16 additions & 2 deletions protocol/src/main/scala/sbt/protocol/Serialization.scala
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ object Serialization {
serializeResponse(message)
}

/** This formats the message according to JSON-RPC. https://www.jsonrpc.org/specification */
private[sbt] def serializeResponseMessageBody(message: JsonRpcResponseMessage): String =
import sbt.internal.protocol.codec.JsonRPCProtocol.given
serializeResponseBody(message)

/** This formats the message according to JSON-RPC. https://www.jsonrpc.org/specification */
private[sbt] def serializeRequestMessage(message: JsonRpcRequestMessage): Array[Byte] = {
import sbt.internal.protocol.codec.JsonRPCProtocol._
Expand All @@ -122,9 +127,18 @@ object Serialization {
serializeResponse(message)
}

private[sbt] def serializeResponse[A: JsonWriter](message: A): Array[Byte] = {
private[sbt] def serializeNotificationMessageBody(
message: JsonRpcNotificationMessage,
): String =
import sbt.internal.protocol.codec.JsonRPCProtocol.given
serializeResponseBody(message)

private[sbt] def serializeResponseBody[A: JsonWriter](message: A): String =
val json: JValue = Converter.toJson[A](message).get
val body = CompactPrinter(json)
CompactPrinter(json)

private[sbt] def serializeResponse[A: JsonWriter](message: A): Array[Byte] = {
val body = serializeResponseBody(message)
val bodyLength = body.getBytes("UTF-8").length

Iterator(
Expand Down
Loading

0 comments on commit 8b4876d

Please sign in to comment.