Skip to content

Make runBackground use process IDs (0.12.x branch) #5120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ end_of_line = lf
insert_final_newline = true
charset = utf-8
indent_style = space
indent_size = 4
indent_size = 2

[*.scala]
end_of_line = lf
Expand Down
3 changes: 1 addition & 2 deletions build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ trait MillPublishJavaModule extends MillJavaModule with PublishModule {
"info.releaseNotesURL" -> Settings.changelogUrl
)
def pomSettings = MillPublishJavaModule.commonPomSettings(artifactName())
def javacOptions = Seq("-source", "1.8", "-target", "1.8", "-encoding", "UTF-8")
def javacOptions = Seq("-source", "11", "-target", "11", "-encoding", "UTF-8")
}

object MillPublishJavaModule {
Expand All @@ -446,7 +446,6 @@ object MillPublishJavaModule {
)
)
}

}

/**
Expand Down
7 changes: 7 additions & 0 deletions docs/modules/ROOT/pages/cli/flags.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,13 @@ forcefully terminating the previous process even though it may be still alive:
$ mill -w foo.runBackground
----

Note that even if you interrupt mill watch via CTRL+C, the server spawned by `runBackground` still runs in the
background. To actually stop the background server use:

[source,console]
----
> mill clean foo.runBackground
----

=== `--jobs`/`-j`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,28 @@ object RunBackgroundTests extends UtestIntegrationTestSuite {
os.write(stop, "")
eventually { probeLockAvailable(lock) }
}

test("sequential") - integrationTest { tester =>
import tester._
val lock1 = os.temp()
val lock2 = os.temp()
val stop = os.temp()
os.remove(stop)
eval(("foo.runBackground", lock1, stop))
eventually { !probeLockAvailable(lock1) }
eval(("foo.runBackground", lock2, stop))
eventually { !probeLockAvailable(lock2) }
Predef.assert(
probeLockAvailable(lock1),
"first process should be exited after second process is running"
)

if (tester.clientServerMode) eval("shutdown")
continually { !probeLockAvailable(lock2) }
os.write(stop, "")
eventually { probeLockAvailable(lock2) }
}

test("clean") - integrationTest { tester =>
import tester._
val lock = os.temp()
Expand All @@ -45,6 +67,7 @@ object RunBackgroundTests extends UtestIntegrationTestSuite {
eval(("foo.runBackground", lock, stop))
eventually {
!probeLockAvailable(lock)

}

eval(("clean", "foo.runBackground"))
Expand Down
42 changes: 36 additions & 6 deletions main/define/src/mill/define/Task.scala
Original file line number Diff line number Diff line change
Expand Up @@ -122,19 +122,33 @@ object Task extends TaskBase {
cls: EnclosingClass
): Command[T] = macro Target.Internal.commandImpl[T]

/** Binary compatibility forwarder. */
def Command(
t: NamedParameterOnlyDummy,
exclusive: Boolean
): CommandFactory = new CommandFactory(exclusive = exclusive, persistent = false)

/**
* @param exclusive Exclusive commands run serially at the end of an evaluation,
* without any other tasks running parallel, and without the
* terminal logging prefixes that are applied to normal tasks.
* These are normally used for "top level" commands which are
* run directly to perform some action or display some output
* to the user.
* @param persistent Persistent comands do not erase the `Task.dest` folder
* between runs.
*/
def Command(
t: NamedParameterOnlyDummy = new NamedParameterOnlyDummy,
exclusive: Boolean = false
): CommandFactory = new CommandFactory(exclusive)
class CommandFactory private[mill] (val exclusive: Boolean) extends TaskBase.TraverseCtxHolder {
exclusive: Boolean = false,
persistent: Boolean = false
): CommandFactory = new CommandFactory(exclusive = exclusive, persistent = persistent)
class CommandFactory private[mill] (val exclusive: Boolean, val persistent: Boolean)
extends TaskBase.TraverseCtxHolder {

/** Binary compatibility forwarder */
private[mill] def this(exclusive: Boolean) = this(exclusive, persistent = false)

def apply[T](t: Result[T])(implicit
w: W[T],
ctx: mill.define.Ctx,
Expand Down Expand Up @@ -662,7 +676,8 @@ object Target extends TaskBase {
w.splice,
cls.splice.value,
taskIsPrivate.splice,
exclusive = c.prefix.splice.asInstanceOf[Task.CommandFactory].exclusive
exclusive = c.prefix.splice.asInstanceOf[Task.CommandFactory].exclusive,
persistent = c.prefix.splice.asInstanceOf[Task.CommandFactory].persistent
)
)
}
Expand Down Expand Up @@ -871,15 +886,30 @@ class Command[+T](
val writer: W[_],
val cls: Class[_],
val isPrivate: Option[Boolean],
val exclusive: Boolean
val exclusive: Boolean,
val persistent: Boolean
) extends NamedTask[T] {
override def flushDest: Boolean = !persistent

/** Binary compatibility forwarder. */
def this(
t: Task[T],
ctx0: mill.define.Ctx,
writer: W[_],
cls: Class[_],
isPrivate: Option[Boolean]
) = this(t, ctx0, writer, cls, isPrivate, false)
) = this(t, ctx0, writer, cls, isPrivate, exclusive = false, persistent = false)

/** Binary compatibility forwarder. */
def this(
t: Task[T],
ctx0: mill.define.Ctx,
writer: W[_],
cls: Class[_],
isPrivate: Option[Boolean],
exclusive: Boolean
) = this(t, ctx0, writer, cls, isPrivate, exclusive = exclusive, persistent = false)

override def asCommand: Some[Command[T]] = Some(this)
// FIXME: deprecated return type: Change to Option
override def writerOpt: Some[W[_]] = Some(writer)
Expand Down
10 changes: 3 additions & 7 deletions pythonlib/src/mill/pythonlib/PythonModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ trait PythonModule extends PipModule with TaskModule { outer =>
*
* @see [[mainScript]]
*/
def runBackground(args: mill.define.Args) = Task.Command {
val (procUuidPath, procLockfile, procUuid) = mill.scalalib.RunModule.backgroundSetup(Task.dest)
def runBackground(args: mill.define.Args) = Task.Command(persistent = true) {
val backgroundPaths = new mill.scalalib.RunModule.BackgroundPaths(destDir = Task.dest)
val pwd0 = os.Path(java.nio.file.Paths.get(".").toAbsolutePath)

os.checker.withValue(os.Checker.Nop) {
Expand All @@ -185,11 +185,7 @@ trait PythonModule extends PipModule with TaskModule { outer =>
classPath = mill.scalalib.JvmWorkerModule.backgroundWrapperClasspath().map(_.path).toSeq,
jvmArgs = Nil,
env = runnerEnvTask(),
mainArgs = Seq(
procUuidPath.toString,
procLockfile.toString,
procUuid,
"500",
mainArgs = backgroundPaths.toArgs ++ Seq(
"<subprocess>",
pythonExe().path.toString,
mainScript().path.toString
Expand Down
Loading
Loading