Jenkins : Find builds currently running that has been executing for more than N seconds

int MAX_ALLOWED_DURATION_IN_SECONDS = 3600 * 6 // 6 hours


  def busyExecutors = Jenkins.instance.computers
                                .collect { 
                                  c -> c.executors.findAll { it.isBusy() }
                                }
                                .flatten() // reminder: transforms list(list(executor)) into list(executor)

def ok = true

println "Busy Executors list"
busyExecutors.each { e -> 
  println e ; 
  int durationInSeconds = (System.currentTimeMillis() - e.executable.getTimeInMillis())/1000.0
  
  if(durationInSeconds > MAX_ALLOWED_DURATION_IN_SECONDS )
  {
    ok = false;
  }
  println "\t duration=$durationInSeconds"
  println "" 
}

println "Done"

return ok