Skip to content

Instantly share code, notes, and snippets.

@pchiusano
Last active December 27, 2015 02:49
Show Gist options
  • Save pchiusano/7254959 to your computer and use it in GitHub Desktop.
Save pchiusano/7254959 to your computer and use it in GitHub Desktop.
Simpler version of Sample action in cjmx
package cjmx.cli
package actions
import scala.concurrent.duration._
import scalaz.stream.Process
// previous version:
// https://github.com/cjmx/cjmx/blob/7ab4adebc784701d2de83c2552bae6acb2bf2e2c/src/main/scala/cjmx/cli/actions/Sample.scala
case class Sample(query: Query, periodSeconds: Int, durationSeconds: Int) extends Action {
def apply(context: ActionContext) = {
val r = query(context)._2 ++
Process.awakeEvery(periodSeconds seconds)
.takeWhile(_.toSeconds <= durationSeconds)
.flatMap { _ => query(context)._2 }
(context, r)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment