Does SBT `playOnStopped` work? Only `playOnStarted` works for me

145 views
Skip to first unread message

KajMagnus

unread,
May 21, 2013, 1:48:20 AM5/21/13
to play-fr...@googlegroups.com
Hi

I'm trying to stop an external process (namely `grunt watch`) when `playOnStopped` happens.

(`playOnStopped` is when the `run` task ends, right? That is, when I hit CTRL+D and the application shuts down.)

However, the code that I've registered with `playOnStopped` never runs.
`playOnStarted` works fine however.

Have a look at these SBT settings:

    playOnStarted <+= baseDirectory { root =>
      (serverAddress: jn.InetSocketAddress) => println("playOnStarted called")  // <-- is printed, works fine
    },
    playOnStopped <+= baseDirectory { root =>
      () => println("playOnStopped called")   // <-- never printed, is `playOnStopped` broken?
    },
 
(Here is another thread that suggests that the above code ought to work:

What happens when I hit CTRL+D and my Play application server shuts down, is that many
   "JNotifyException_linux: Error removing watch 203"
errors are printed (plus stack trace).  These errors are supposedly harmless though (?).

Could it be that the  JNotifyException_linux  errors somehow prevents `playOnStopped` from being called?
Or am I doing something wrong, or is there a bug?


(Background: I'm transpiling LiveScript to Javascript and minifying and bundling JS and CSS using Node.js' Grunt.)

Best regards,
KajMagnus

Kaj Magnus Lindberg

unread,
May 22, 2013, 3:42:35 AM5/22/13
to play-fr...@googlegroups.com
I just tested with a small and completely new Play 2.1.1. project, and `playOnStopped` does work in that new project.
So the missing playOnStopped invocation problem, is somehow related to my other "real" project and its submodules, and perhaps to the JNotifyException_linux error.

When I do `play run` and then hit CTRL+D, the console output does end with an error:
  ...
  [error] net.contentobjects.jnotify.linux.JNotifyException_linux: Error removing watch 294
  [error] Use 'last' for the full log.
I don't know if this error might preclude the `playOnStopped` callback from being invoked.   (Does someone else know?)


(This is the small and completely new Build.scala that works fine, however:

import sbt._
import Keys._
import play.Project._

object ApplicationBuild extends Build {

  val appName         = "play-on-stopped-test"
  val appVersion      = "1.0-SNAPSHOT"

  val appDependencies = Seq(
    // Add your project dependencies here,
    jdbc,
    anorm
  )

  val main = play.Project(appName, appVersion, appDependencies).settings(
    // Add your own project settings here      
    playOnStarted <+= baseDirectory { root =>
      (serverAddress: java.net.InetSocketAddress) => println("playOnStarted called")
    },
    playOnStopped <+= baseDirectory { root =>
      () => println("playOnStopped called")
    }
  )
}

)



--
You received this message because you are subscribed to a topic in the Google Groups "play-framework" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/play-framework/6Z34QLdl4e8/unsubscribe?hl=en-US.
To unsubscribe from this group and all its topics, send an email to play-framewor...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

virtualeyes

unread,
Jun 13, 2013, 6:13:08 AM6/13/13
to play-fr...@googlegroups.com
In recent Play 2.1 (built from source 2 days ago) onStopped works with Grunt at first, but after some time in ~run mode, changing several .coffee/.less files, etc., then ctrl-d appears to do nothing; in fact, Grunt's run task is invoked again upon pressing ctrl-d followed by enter key.

So, doing ctrl-d 2X seems to work, sometimes ;-)

Basically, it's quirky, not sure what the deal is.

The only stop the world action that really works is ctrl-c, but then you exit Play console entirely.
Reply all
Reply to author
Forward
0 new messages