2010-10-07 02:29:56 +08:00
|
|
|
package org.broadinstitute.sting.queue.engine
|
|
|
|
|
|
|
|
|
|
import org.broadinstitute.sting.queue.function.InProcessFunction
|
2010-10-21 14:37:28 +08:00
|
|
|
import org.broadinstitute.sting.queue.util.Logging
|
2010-10-07 02:29:56 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Runs a function that executes in process and does not fork out an external process.
|
|
|
|
|
*/
|
2010-12-10 12:36:06 +08:00
|
|
|
class InProcessRunner(val function: InProcessFunction) extends JobRunner[InProcessFunction] with Logging {
|
2010-10-07 02:29:56 +08:00
|
|
|
private var runStatus: RunnerStatus.Value = _
|
|
|
|
|
|
|
|
|
|
def start() = {
|
|
|
|
|
try {
|
2010-10-16 01:01:36 +08:00
|
|
|
if (logger.isDebugEnabled) {
|
|
|
|
|
logger.debug("Starting: " + function.commandDirectory + " > " + function.description)
|
|
|
|
|
} else {
|
|
|
|
|
logger.info("Starting: " + function.description)
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-21 14:37:28 +08:00
|
|
|
function.deleteLogs()
|
|
|
|
|
function.deleteOutputs()
|
2010-10-16 01:01:36 +08:00
|
|
|
function.mkOutputDirectories()
|
2010-12-10 12:36:06 +08:00
|
|
|
runStatus = RunnerStatus.RUNNING
|
2010-10-07 02:29:56 +08:00
|
|
|
function.run()
|
2010-10-07 09:19:18 +08:00
|
|
|
function.doneOutputs.foreach(_.createNewFile())
|
2010-10-16 01:01:36 +08:00
|
|
|
writeDone()
|
2010-10-07 02:29:56 +08:00
|
|
|
runStatus = RunnerStatus.DONE
|
|
|
|
|
logger.info("Done: " + function.description)
|
|
|
|
|
} catch {
|
|
|
|
|
case e => {
|
|
|
|
|
runStatus = RunnerStatus.FAILED
|
|
|
|
|
try {
|
2010-10-07 09:19:18 +08:00
|
|
|
function.failOutputs.foreach(_.createNewFile())
|
2010-10-16 01:01:36 +08:00
|
|
|
writeStackTrace(e)
|
2010-10-07 02:29:56 +08:00
|
|
|
} catch {
|
|
|
|
|
case _ => /* ignore errors in the exception handler */
|
|
|
|
|
}
|
|
|
|
|
logger.error("Error: " + function.description, e)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def status = runStatus
|
|
|
|
|
}
|