2010-08-10 00:42:48 +08:00
|
|
|
package org.broadinstitute.sting.queue.engine
|
|
|
|
|
|
2010-10-16 01:01:36 +08:00
|
|
|
import org.broadinstitute.sting.queue.util.{Logging, ShellJob}
|
2010-08-10 00:42:48 +08:00
|
|
|
import org.broadinstitute.sting.queue.function.CommandLineFunction
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Runs jobs one at a time locally
|
|
|
|
|
*/
|
2010-10-16 01:01:36 +08:00
|
|
|
class ShellJobRunner(val function: CommandLineFunction) extends JobRunner with Logging {
|
2010-10-07 02:29:56 +08:00
|
|
|
private var runStatus: RunnerStatus.Value = _
|
|
|
|
|
|
2010-08-10 00:42:48 +08:00
|
|
|
/**
|
|
|
|
|
* Runs the function on the local shell.
|
|
|
|
|
* @param function Command to run.
|
|
|
|
|
*/
|
2010-10-07 02:29:56 +08:00
|
|
|
def start() = {
|
2010-10-16 01:01:36 +08:00
|
|
|
try {
|
|
|
|
|
val job = new ShellJob
|
|
|
|
|
job.command = function.commandLine
|
|
|
|
|
job.workingDir = function.commandDirectory
|
|
|
|
|
job.outputFile = function.jobOutputFile
|
|
|
|
|
job.errorFile = function.jobErrorFile
|
2010-08-10 00:42:48 +08:00
|
|
|
|
2010-10-16 01:01:36 +08:00
|
|
|
if (logger.isDebugEnabled) {
|
|
|
|
|
logger.debug("Starting: " + function.commandDirectory + " > " + function.commandLine)
|
|
|
|
|
} else {
|
|
|
|
|
logger.info("Starting: " + function.commandLine)
|
|
|
|
|
}
|
2010-10-07 02:29:56 +08:00
|
|
|
|
2010-10-16 01:01:36 +08:00
|
|
|
logger.info("Output written to " + function.jobOutputFile)
|
2010-10-21 14:37:28 +08:00
|
|
|
if (function.jobErrorFile != null)
|
2010-10-16 01:01:36 +08:00
|
|
|
logger.info("Errors written to " + function.jobErrorFile)
|
2010-08-10 00:42:48 +08:00
|
|
|
|
2010-10-21 14:37:28 +08:00
|
|
|
function.deleteLogs()
|
|
|
|
|
function.deleteOutputs()
|
2010-10-16 01:01:36 +08:00
|
|
|
runStatus = RunnerStatus.RUNNING
|
|
|
|
|
function.mkOutputDirectories()
|
|
|
|
|
job.run()
|
|
|
|
|
function.doneOutputs.foreach(_.createNewFile())
|
|
|
|
|
runStatus = RunnerStatus.DONE
|
|
|
|
|
logger.info("Done: " + function.commandLine)
|
2010-10-07 02:29:56 +08:00
|
|
|
} catch {
|
2010-10-16 01:01:36 +08:00
|
|
|
case e =>
|
2010-10-07 02:29:56 +08:00
|
|
|
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.commandLine, e)
|
|
|
|
|
}
|
2010-08-10 00:42:48 +08:00
|
|
|
}
|
2010-10-07 02:29:56 +08:00
|
|
|
|
|
|
|
|
def status = runStatus
|
2010-08-10 00:42:48 +08:00
|
|
|
}
|