Closed tianhao-au closed 7 years ago
I also noticed this behaviour with the last Akka HTTP 10.0.0.
sbt 0.13.13 scala 2.12
Thanks for reporting! @jrudolph perhaps might have an idea once he's back from moving (aproximately in a week or so), since he seems to have maintained quite a bit of revolver.
Sorry for keeping this open so long.
You seem to try to use sbt-revolver from the shell. However, using sbt-revolver makes only sense if you use it from within sbt. Try to start to the sbt shell first with sbt
and run reStart
only then.
I want to reopen this, it's not working from within sbt
as well.
> sbt
[info] Loading project definition from /app/project
[info] Set current project to root (in build file:/app/)
> reStart com.my.Server
[info] Application root not yet started
[info] Starting application root in the background ...
root Starting com.my.Server.main(com.my.Server)
[success] Total time: 1 s, completed Jan 14, 2018 4:38:09 AM
> root INFO [Slf4jLogger]: Slf4jLogger started
root Server online at http://localhost:8080/
root Press RETURN to stop...
root ... finished with exit code 0
It looks like you're using StdIn.readline
to wait for the user to press Enter, which works well with run
, but reStart
starts your server without standard input connected, so the StdIn.readline
returns immediately and the server gets shut down again
Yes, I think @Toxaris is exactly right here. Personally I typically simply remove the StdIn.readline
from the code - it doesn't make much sense in production, either, after all. This seems to work nicely.
and yet it doesn't work at all, even with StdIn.readline
removed.
Straight from the akka-http docs:
val bindingFuture = Http().newServerAt("localhost", 8083).bind(route)
// StdIn.readLine()
bindingFuture
.flatMap(_.unbind())
.onComplete(_ => system.terminate())
So, how does one use ~reStart
from sbt console and not have the application immediately terminate?
Of course, run
works, but you don't get hot code reload, which makes live development a tedious process of task switching to compile/run latest changes.
If I'm missing something obvious let me know.
and yet it doesn't work at all, even with
StdIn.readline
removed.Straight from the akka-http docs:
val bindingFuture = Http().newServerAt("localhost", 8083).bind(route) // StdIn.readLine() bindingFuture .flatMap(_.unbind()) .onComplete(_ => system.terminate())
So, how does one use
~reStart
from sbt console and not have the application immediately terminate?Of course,
run
works
I don't think run
would work for that snippet, since what bindingFuture.flatMap(_.unbind())
is saying is: "as soon as the binding is created successfully, unbind again".
I don't think run would work for that snippet, since what bindingFuture.flatMap(_.unbind()) is saying is: "as soon as the binding is created successfully, unbind again".
Yes, that's correct, for run
you need readLine
.
Still, how does one use ~reStart
such that the application doesn't immediately terminate? Obviously in most scenarios in development and production one wants the application to run basically indefintely.
Still, how does one use
~reStart
such that the application doesn't immediately terminate? Obviously in most scenarios in development and production one wants the application to run basically indefintely.
Just remove all the lines but the first.
Just remove all the lines but the first.
Sure, but I need to do some cleanup on shutdown; actual code looks like:
val bindingFuture = Http().newServerAt("localhost", 8083).bind(route)
bindingFuture
.flatMap(_.unbind())
.onComplete(_ =>
connectionPool.close(dataSource)
system.terminate()
)
I see an SO post referencing CoordinatedShutdown, perhaps that's the approach I need to take.
Anyway, sounds like reStart
works just fine -- ignore me, just a Play Framework refugee starting out fresh with Akka HTTP on Scala 3 :)
@godenji Akka adds a JVM shutdown hook that runs their "coordinated shutdown" process. You can add tasks to that to be run during specific shutdown phases if oyu need to do cleanup (e.g. close a connecetion pool). You do not need to call system.terminate()
yourself.
See the e.g.
CoordinatedShutdown(context.system).addTask(CoordinatedShutdown.PhaseBeforeServiceUnbind, "someTaskName") { () =>
implicit val timeout: Timeout = 5.seconds
myActor.ask(MyActor.Stop(_))
}
on https://doc.akka.io/docs/akka/current/coordinated-shutdown.html
I just add the plugin
addSbtPlugin("io.spray" % "sbt-revolver" % "0.8.0")
And start the app using
sbt re-start
Then the console display
... killing ...
I have no idea what's going on, do I miss something here?