Job.scala 2.33 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
package nl.lumc.sasc.biopet.core.pipelinestatus

import java.io.File

import nl.lumc.sasc.biopet.utils.ConfigUtils

import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global
import scala.util.matching.Regex

/**
pjvan_thof's avatar
pjvan_thof committed
12
13
  * This class can store a single job from a deps.json
  *
14
15
16
17
  * Created by pjvanthof on 24/06/2017.
  */
class Job(val name: String, map: Map[String, Any]) {

pjvan_thof's avatar
pjvan_thof committed
18
  /** When true this job was done at the moment of the deps.json creation */
19
20
  def doneAtStart: Boolean = ConfigUtils.any2boolean(map("done_at_start"))

pjvan_thof's avatar
pjvan_thof committed
21
  /** If one of this files exist the job is marked as failed */
22
  def failFiles: List[File] = ConfigUtils.any2fileList(map("fail_files"))
pjvan_thof's avatar
pjvan_thof committed
23
24

  /** If all of this files exist the job is marked as done */
25
  def doneFiles: List[File] = ConfigUtils.any2fileList(map("done_files"))
pjvan_thof's avatar
pjvan_thof committed
26
27

  /** Returns a list of jobs that depends on this job */
28
  def outputUsedByJobs: List[String] = ConfigUtils.any2stringList(map("output_used_by_jobs"))
pjvan_thof's avatar
pjvan_thof committed
29
30

  /** Returns a list of job where this job depends on */
31
  def dependsOnJobs: List[String] = ConfigUtils.any2stringList(map("depends_on_jobs"))
pjvan_thof's avatar
pjvan_thof committed
32
33

  /** Location of the stdout file of this job */
34
35
  def stdoutFile = new File(ConfigUtils.any2string(map("stdout_file")))

pjvan_thof's avatar
pjvan_thof committed
36
  /** All output files of this job */
37
  def outputsFiles: List[File] = ConfigUtils.any2fileList(map("outputs"))
pjvan_thof's avatar
pjvan_thof committed
38
39

  /** All input files of this job */
40
41
  def inputFiles: List[File] = ConfigUtils.any2fileList(map("inputs"))

pjvan_thof's avatar
pjvan_thof committed
42
  /** When true this job is marked as a main job in the graph */
43
  def mainJob: Boolean = ConfigUtils.any2boolean(map("main_job"))
pjvan_thof's avatar
pjvan_thof committed
44
45

  /** When true this job is marked as a intermediate job */
46
47
  def intermediate: Boolean = ConfigUtils.any2boolean(map("intermediate"))

pjvan_thof's avatar
pjvan_thof committed
48
  /** Return a [[Future[Boolean]] to check if the job is done */
49
  def isDone: Future[Boolean] = Future { doneFiles.forall(_.exists()) }
pjvan_thof's avatar
pjvan_thof committed
50
51

  /** Return a [[Future[Boolean]] to check if the job is failed */
52
53
  def isFailed: Future[Boolean] = Future { failFiles.exists(_.exists()) }

pjvan_thof's avatar
pjvan_thof committed
54
  /** Returns the compressed name of this job */
55
56
57
58
59
60
  def compressedName: (String, Int) = Job.compressedName(name)
}

object Job {
  val numberRegex: Regex = """(.*)_(\d*)$""".r

pjvan_thof's avatar
pjvan_thof committed
61
  /** This splits a job name from it's id */
62
63
64
65
66
  def compressedName(jobName: String): (String, Int) = jobName match {
    case Job.numberRegex(name, number) => (name, number.toInt)
  }

}