Skip to content

Instantly share code, notes, and snippets.

@isterin
Created November 29, 2011 17:55
Show Gist options
  • Save isterin/1405719 to your computer and use it in GitHub Desktop.
Save isterin/1405719 to your computer and use it in GitHub Desktop.
Grid Task
import org.gridgain.grid.GridClosureCallMode._
import org.gridgain.scalar.scalar
import scalar._
import java.io.File
import io.Source
import net.liftweb.json._
import net.liftweb.json.JsonDSL._
import java.util.{Date, Collections}
import java.util.concurrent.{Callable, TimeUnit, Executors, ConcurrentHashMap}
class GridTask(scriptCommand:String, scriptEnv:String, scriptDir:String) extends Callable[JValue] {
def call() = {
val proc = new ProcessBuilder(scriptCommand.split(" "): _*)
proc.command()
proc.directory(new File(scriptDir))
proc.environment().put("APPLICATION_ENV", scriptEnv);
val p = proc.start()
p.waitFor();
val retString = Source.fromInputStream(p.getInputStream).getLines()
val errString = Source.fromInputStream(p.getErrorStream).getLines()
if (p.exitValue == 0 && !retString.isEmpty) {
parse(retString.mkString("\n"))
} else {
("event_id" -> 53) ~
("start_time" -> new Date().getTime) ~
("error" -> errString)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment