Created
November 29, 2011 17:55
-
-
Save isterin/1405719 to your computer and use it in GitHub Desktop.
Grid Task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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