src/Pure/Admin/isabelle_cronjob.scala
author wenzelm
Sat, 15 Oct 2016 11:26:31 +0200
changeset 64219 c1af670cbe7e
parent 64218 f318cb6ba511
child 64220 e7cbf81ec4b7
permissions -rw-r--r--
clarified logs;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
64148
bbf43b7c4d0d basic setup for Isabelle cronjob;
wenzelm
parents:
diff changeset
     1
/*  Title:      Pure/Admin/isabelle_cronjob.scala
bbf43b7c4d0d basic setup for Isabelle cronjob;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
bbf43b7c4d0d basic setup for Isabelle cronjob;
wenzelm
parents:
diff changeset
     3
bbf43b7c4d0d basic setup for Isabelle cronjob;
wenzelm
parents:
diff changeset
     4
Main entry point for administrative cronjob at TUM.
bbf43b7c4d0d basic setup for Isabelle cronjob;
wenzelm
parents:
diff changeset
     5
*/
bbf43b7c4d0d basic setup for Isabelle cronjob;
wenzelm
parents:
diff changeset
     6
bbf43b7c4d0d basic setup for Isabelle cronjob;
wenzelm
parents:
diff changeset
     7
package isabelle
bbf43b7c4d0d basic setup for Isabelle cronjob;
wenzelm
parents:
diff changeset
     8
bbf43b7c4d0d basic setup for Isabelle cronjob;
wenzelm
parents:
diff changeset
     9
64170
a0c2cbe2fc8e more explicit management of tasks;
wenzelm
parents: 64162
diff changeset
    10
import scala.annotation.tailrec
a0c2cbe2fc8e more explicit management of tasks;
wenzelm
parents: 64162
diff changeset
    11
import scala.collection.mutable
a0c2cbe2fc8e more explicit management of tasks;
wenzelm
parents: 64162
diff changeset
    12
a0c2cbe2fc8e more explicit management of tasks;
wenzelm
parents: 64162
diff changeset
    13
64148
bbf43b7c4d0d basic setup for Isabelle cronjob;
wenzelm
parents:
diff changeset
    14
object Isabelle_Cronjob
bbf43b7c4d0d basic setup for Isabelle cronjob;
wenzelm
parents:
diff changeset
    15
{
64194
b5ada7dcceaa integrity test of build_history vs. build_history_base;
wenzelm
parents: 64193
diff changeset
    16
  /* file-system state: owned by main cronjob */
64153
769791954872 some timing and logging, similar to old isatest.log;
wenzelm
parents: 64148
diff changeset
    17
769791954872 some timing and logging, similar to old isatest.log;
wenzelm
parents: 64148
diff changeset
    18
  val main_dir = Path.explode("~/cronjob")
64194
b5ada7dcceaa integrity test of build_history vs. build_history_base;
wenzelm
parents: 64193
diff changeset
    19
  val main_state_file = main_dir + Path.explode("run/main.state")
64219
c1af670cbe7e clarified logs;
wenzelm
parents: 64218
diff changeset
    20
  val current_log = main_dir + Path.explode("run/main.log")  // owned by log service
c1af670cbe7e clarified logs;
wenzelm
parents: 64218
diff changeset
    21
  val cumulative_log = main_dir + Path.explode("log/main.log")  // owned by log service
64153
769791954872 some timing and logging, similar to old isatest.log;
wenzelm
parents: 64148
diff changeset
    22
64194
b5ada7dcceaa integrity test of build_history vs. build_history_base;
wenzelm
parents: 64193
diff changeset
    23
  val isabelle_repos = main_dir + Path.explode("isabelle-build_history")
b5ada7dcceaa integrity test of build_history vs. build_history_base;
wenzelm
parents: 64193
diff changeset
    24
  val afp_repos = main_dir + Path.explode("AFP-build_history")
64153
769791954872 some timing and logging, similar to old isatest.log;
wenzelm
parents: 64148
diff changeset
    25
64218
f318cb6ba511 publish directly on webspace;
wenzelm
parents: 64215
diff changeset
    26
  val release_snapshot = Path.explode("~/html-data/release_snapshot")
64215
123e6dcd3852 cronjob: build release from repository snapshot;
wenzelm
parents: 64199
diff changeset
    27
64153
769791954872 some timing and logging, similar to old isatest.log;
wenzelm
parents: 64148
diff changeset
    28
64192
wenzelm
parents: 64187
diff changeset
    29
wenzelm
parents: 64187
diff changeset
    30
  /** particular tasks **/
wenzelm
parents: 64187
diff changeset
    31
64194
b5ada7dcceaa integrity test of build_history vs. build_history_base;
wenzelm
parents: 64193
diff changeset
    32
  /* identify Isabelle + AFP repository snapshots */
64192
wenzelm
parents: 64187
diff changeset
    33
64194
b5ada7dcceaa integrity test of build_history vs. build_history_base;
wenzelm
parents: 64193
diff changeset
    34
  private val isabelle_identify =
64192
wenzelm
parents: 64187
diff changeset
    35
    Logger_Task("isabelle_identify", logger =>
wenzelm
parents: 64187
diff changeset
    36
      {
64198
wenzelm
parents: 64197
diff changeset
    37
        val isabelle_id = Mercurial.repository(isabelle_repos).pull_id()
wenzelm
parents: 64197
diff changeset
    38
        val afp_id = Mercurial.repository(afp_repos).pull_id()
64192
wenzelm
parents: 64187
diff changeset
    39
64195
wenzelm
parents: 64194
diff changeset
    40
        File.write(logger.log_dir + Build_Log.log_filename("isabelle_identify", logger.start_date),
64192
wenzelm
parents: 64187
diff changeset
    41
          terminate_lines(
wenzelm
parents: 64187
diff changeset
    42
            List("isabelle_identify: " + Build_Log.print_date(logger.start_date),
wenzelm
parents: 64187
diff changeset
    43
              "",
wenzelm
parents: 64187
diff changeset
    44
              "Isabelle version: " + isabelle_id,
wenzelm
parents: 64187
diff changeset
    45
              "AFP version: " + afp_id)))
wenzelm
parents: 64187
diff changeset
    46
      })
wenzelm
parents: 64187
diff changeset
    47
wenzelm
parents: 64187
diff changeset
    48
64194
b5ada7dcceaa integrity test of build_history vs. build_history_base;
wenzelm
parents: 64193
diff changeset
    49
  /* integrity test of build_history vs. build_history_base */
64193
7a7e370e2523 clarified log_subdir vs. log_filename;
wenzelm
parents: 64192
diff changeset
    50
64194
b5ada7dcceaa integrity test of build_history vs. build_history_base;
wenzelm
parents: 64193
diff changeset
    51
  private val build_history_base =
64193
7a7e370e2523 clarified log_subdir vs. log_filename;
wenzelm
parents: 64192
diff changeset
    52
    Logger_Task("build_history_base", logger =>
7a7e370e2523 clarified log_subdir vs. log_filename;
wenzelm
parents: 64192
diff changeset
    53
      {
64194
b5ada7dcceaa integrity test of build_history vs. build_history_base;
wenzelm
parents: 64193
diff changeset
    54
        for {
b5ada7dcceaa integrity test of build_history vs. build_history_base;
wenzelm
parents: 64193
diff changeset
    55
          (result, log_path) <-
b5ada7dcceaa integrity test of build_history vs. build_history_base;
wenzelm
parents: 64193
diff changeset
    56
            Build_History.build_history(Mercurial.repository(isabelle_repos),
b5ada7dcceaa integrity test of build_history vs. build_history_base;
wenzelm
parents: 64193
diff changeset
    57
              rev = "build_history_base", fresh = true, build_args = List("FOL"))
b5ada7dcceaa integrity test of build_history vs. build_history_base;
wenzelm
parents: 64193
diff changeset
    58
        } {
b5ada7dcceaa integrity test of build_history vs. build_history_base;
wenzelm
parents: 64193
diff changeset
    59
          result.check
64195
wenzelm
parents: 64194
diff changeset
    60
          File.copy(log_path, logger.log_dir + log_path.base)
64194
b5ada7dcceaa integrity test of build_history vs. build_history_base;
wenzelm
parents: 64193
diff changeset
    61
        }
64193
7a7e370e2523 clarified log_subdir vs. log_filename;
wenzelm
parents: 64192
diff changeset
    62
      })
7a7e370e2523 clarified log_subdir vs. log_filename;
wenzelm
parents: 64192
diff changeset
    63
7a7e370e2523 clarified log_subdir vs. log_filename;
wenzelm
parents: 64192
diff changeset
    64
64215
123e6dcd3852 cronjob: build release from repository snapshot;
wenzelm
parents: 64199
diff changeset
    65
  /* build release from repository snapshot */
123e6dcd3852 cronjob: build release from repository snapshot;
wenzelm
parents: 64199
diff changeset
    66
123e6dcd3852 cronjob: build release from repository snapshot;
wenzelm
parents: 64199
diff changeset
    67
  private val build_release =
123e6dcd3852 cronjob: build release from repository snapshot;
wenzelm
parents: 64199
diff changeset
    68
    Logger_Task("build_release", logger =>
123e6dcd3852 cronjob: build release from repository snapshot;
wenzelm
parents: 64199
diff changeset
    69
      Isabelle_System.with_tmp_dir("isadist")(tmp_dir =>
123e6dcd3852 cronjob: build release from repository snapshot;
wenzelm
parents: 64199
diff changeset
    70
        {
123e6dcd3852 cronjob: build release from repository snapshot;
wenzelm
parents: 64199
diff changeset
    71
          val base_dir = File.path(tmp_dir)
123e6dcd3852 cronjob: build release from repository snapshot;
wenzelm
parents: 64199
diff changeset
    72
123e6dcd3852 cronjob: build release from repository snapshot;
wenzelm
parents: 64199
diff changeset
    73
          val new_snapshot = release_snapshot.ext("new")
123e6dcd3852 cronjob: build release from repository snapshot;
wenzelm
parents: 64199
diff changeset
    74
          val old_snapshot = release_snapshot.ext("old")
123e6dcd3852 cronjob: build release from repository snapshot;
wenzelm
parents: 64199
diff changeset
    75
123e6dcd3852 cronjob: build release from repository snapshot;
wenzelm
parents: 64199
diff changeset
    76
          Isabelle_System.rm_tree(new_snapshot)
123e6dcd3852 cronjob: build release from repository snapshot;
wenzelm
parents: 64199
diff changeset
    77
          Isabelle_System.rm_tree(old_snapshot)
123e6dcd3852 cronjob: build release from repository snapshot;
wenzelm
parents: 64199
diff changeset
    78
123e6dcd3852 cronjob: build release from repository snapshot;
wenzelm
parents: 64199
diff changeset
    79
          Build_Release.build_release(base_dir, parallel_jobs = 4,
123e6dcd3852 cronjob: build release from repository snapshot;
wenzelm
parents: 64199
diff changeset
    80
            remote_mac = "macbroy30", website = Some(new_snapshot))
123e6dcd3852 cronjob: build release from repository snapshot;
wenzelm
parents: 64199
diff changeset
    81
123e6dcd3852 cronjob: build release from repository snapshot;
wenzelm
parents: 64199
diff changeset
    82
          if (release_snapshot.is_dir) File.mv(release_snapshot, old_snapshot)
123e6dcd3852 cronjob: build release from repository snapshot;
wenzelm
parents: 64199
diff changeset
    83
          File.mv(new_snapshot, release_snapshot)
123e6dcd3852 cronjob: build release from repository snapshot;
wenzelm
parents: 64199
diff changeset
    84
          Isabelle_System.rm_tree(old_snapshot)
123e6dcd3852 cronjob: build release from repository snapshot;
wenzelm
parents: 64199
diff changeset
    85
        }))
123e6dcd3852 cronjob: build release from repository snapshot;
wenzelm
parents: 64199
diff changeset
    86
123e6dcd3852 cronjob: build release from repository snapshot;
wenzelm
parents: 64199
diff changeset
    87
64192
wenzelm
parents: 64187
diff changeset
    88
wenzelm
parents: 64187
diff changeset
    89
  /** task logging **/
64171
568cd5123952 clarified task logging via log service;
wenzelm
parents: 64170
diff changeset
    90
64193
7a7e370e2523 clarified log_subdir vs. log_filename;
wenzelm
parents: 64192
diff changeset
    91
  sealed case class Logger_Task(name: String = "", body: Logger => Unit)
64154
e5cf40a54b1e identify managed repository clones;
wenzelm
parents: 64153
diff changeset
    92
64171
568cd5123952 clarified task logging via log service;
wenzelm
parents: 64170
diff changeset
    93
  class Log_Service private[Isabelle_Cronjob](progress: Progress)
568cd5123952 clarified task logging via log service;
wenzelm
parents: 64170
diff changeset
    94
  {
64219
c1af670cbe7e clarified logs;
wenzelm
parents: 64218
diff changeset
    95
    current_log.file.delete
c1af670cbe7e clarified logs;
wenzelm
parents: 64218
diff changeset
    96
64171
568cd5123952 clarified task logging via log service;
wenzelm
parents: 64170
diff changeset
    97
    private val thread: Consumer_Thread[String] =
568cd5123952 clarified task logging via log service;
wenzelm
parents: 64170
diff changeset
    98
      Consumer_Thread.fork("cronjob: logger", daemon = true)(
568cd5123952 clarified task logging via log service;
wenzelm
parents: 64170
diff changeset
    99
        consume = (text: String) =>
64219
c1af670cbe7e clarified logs;
wenzelm
parents: 64218
diff changeset
   100
          { // critical
c1af670cbe7e clarified logs;
wenzelm
parents: 64218
diff changeset
   101
            File.append(current_log, text + "\n")
c1af670cbe7e clarified logs;
wenzelm
parents: 64218
diff changeset
   102
            File.append(cumulative_log, text + "\n")
64171
568cd5123952 clarified task logging via log service;
wenzelm
parents: 64170
diff changeset
   103
            progress.echo(text)
568cd5123952 clarified task logging via log service;
wenzelm
parents: 64170
diff changeset
   104
            true
568cd5123952 clarified task logging via log service;
wenzelm
parents: 64170
diff changeset
   105
          })
568cd5123952 clarified task logging via log service;
wenzelm
parents: 64170
diff changeset
   106
568cd5123952 clarified task logging via log service;
wenzelm
parents: 64170
diff changeset
   107
    def shutdown() { thread.shutdown() }
568cd5123952 clarified task logging via log service;
wenzelm
parents: 64170
diff changeset
   108
568cd5123952 clarified task logging via log service;
wenzelm
parents: 64170
diff changeset
   109
    val hostname = Isabelle_System.hostname()
568cd5123952 clarified task logging via log service;
wenzelm
parents: 64170
diff changeset
   110
568cd5123952 clarified task logging via log service;
wenzelm
parents: 64170
diff changeset
   111
    def log(date: Date, task_name: String, msg: String): Unit =
64193
7a7e370e2523 clarified log_subdir vs. log_filename;
wenzelm
parents: 64192
diff changeset
   112
      if (task_name != "")
7a7e370e2523 clarified log_subdir vs. log_filename;
wenzelm
parents: 64192
diff changeset
   113
        thread.send(
7a7e370e2523 clarified log_subdir vs. log_filename;
wenzelm
parents: 64192
diff changeset
   114
          "[" + Build_Log.print_date(date) + ", " + hostname + ", " + task_name + "]: " + msg)
64171
568cd5123952 clarified task logging via log service;
wenzelm
parents: 64170
diff changeset
   115
568cd5123952 clarified task logging via log service;
wenzelm
parents: 64170
diff changeset
   116
    def start_logger(start_date: Date, task_name: String): Logger =
568cd5123952 clarified task logging via log service;
wenzelm
parents: 64170
diff changeset
   117
      new Logger(this, start_date, task_name)
64154
e5cf40a54b1e identify managed repository clones;
wenzelm
parents: 64153
diff changeset
   118
64171
568cd5123952 clarified task logging via log service;
wenzelm
parents: 64170
diff changeset
   119
    def run_task(start_date: Date, task: Logger_Task)
568cd5123952 clarified task logging via log service;
wenzelm
parents: 64170
diff changeset
   120
    {
568cd5123952 clarified task logging via log service;
wenzelm
parents: 64170
diff changeset
   121
      val logger = start_logger(start_date, task.name)
568cd5123952 clarified task logging via log service;
wenzelm
parents: 64170
diff changeset
   122
      val res = Exn.capture { task.body(logger) }
568cd5123952 clarified task logging via log service;
wenzelm
parents: 64170
diff changeset
   123
      val end_date = Date.now()
568cd5123952 clarified task logging via log service;
wenzelm
parents: 64170
diff changeset
   124
      val err =
568cd5123952 clarified task logging via log service;
wenzelm
parents: 64170
diff changeset
   125
        res match {
568cd5123952 clarified task logging via log service;
wenzelm
parents: 64170
diff changeset
   126
          case Exn.Res(_) => None
568cd5123952 clarified task logging via log service;
wenzelm
parents: 64170
diff changeset
   127
          case Exn.Exn(exn) => Some(Exn.message(exn))
568cd5123952 clarified task logging via log service;
wenzelm
parents: 64170
diff changeset
   128
        }
568cd5123952 clarified task logging via log service;
wenzelm
parents: 64170
diff changeset
   129
      logger.log_end(end_date, err)
568cd5123952 clarified task logging via log service;
wenzelm
parents: 64170
diff changeset
   130
    }
568cd5123952 clarified task logging via log service;
wenzelm
parents: 64170
diff changeset
   131
568cd5123952 clarified task logging via log service;
wenzelm
parents: 64170
diff changeset
   132
    def fork_task(start_date: Date, task: Logger_Task): Task =
568cd5123952 clarified task logging via log service;
wenzelm
parents: 64170
diff changeset
   133
      new Task(task.name, run_task(start_date, task))
568cd5123952 clarified task logging via log service;
wenzelm
parents: 64170
diff changeset
   134
  }
568cd5123952 clarified task logging via log service;
wenzelm
parents: 64170
diff changeset
   135
568cd5123952 clarified task logging via log service;
wenzelm
parents: 64170
diff changeset
   136
  class Logger private[Isabelle_Cronjob](
568cd5123952 clarified task logging via log service;
wenzelm
parents: 64170
diff changeset
   137
    val log_service: Log_Service, val start_date: Date, val task_name: String)
64162
03057a8fdd1f simplified: no internal state for Mercurial;
wenzelm
parents: 64157
diff changeset
   138
  {
64171
568cd5123952 clarified task logging via log service;
wenzelm
parents: 64170
diff changeset
   139
    def log(date: Date, msg: String): Unit = log_service.log(date, task_name, msg)
568cd5123952 clarified task logging via log service;
wenzelm
parents: 64170
diff changeset
   140
568cd5123952 clarified task logging via log service;
wenzelm
parents: 64170
diff changeset
   141
    def log_end(end_date: Date, err: Option[String])
568cd5123952 clarified task logging via log service;
wenzelm
parents: 64170
diff changeset
   142
    {
568cd5123952 clarified task logging via log service;
wenzelm
parents: 64170
diff changeset
   143
      val elapsed_time = end_date.time - start_date.time
568cd5123952 clarified task logging via log service;
wenzelm
parents: 64170
diff changeset
   144
      val msg =
568cd5123952 clarified task logging via log service;
wenzelm
parents: 64170
diff changeset
   145
        (if (err.isEmpty) "finished" else "ERROR " + err.get) +
64197
c43dedbb8118 tuned message;
wenzelm
parents: 64195
diff changeset
   146
        (if (elapsed_time.seconds < 3.0) "" else " (" + elapsed_time.message_hms + " elapsed time)")
64171
568cd5123952 clarified task logging via log service;
wenzelm
parents: 64170
diff changeset
   147
      log(end_date, msg)
568cd5123952 clarified task logging via log service;
wenzelm
parents: 64170
diff changeset
   148
    }
568cd5123952 clarified task logging via log service;
wenzelm
parents: 64170
diff changeset
   149
64195
wenzelm
parents: 64194
diff changeset
   150
    val log_dir: Path = main_dir + Build_Log.log_subdir(start_date)
wenzelm
parents: 64194
diff changeset
   151
wenzelm
parents: 64194
diff changeset
   152
    Isabelle_System.mkdirs(log_dir)
64171
568cd5123952 clarified task logging via log service;
wenzelm
parents: 64170
diff changeset
   153
    log(start_date, "started")
568cd5123952 clarified task logging via log service;
wenzelm
parents: 64170
diff changeset
   154
  }
568cd5123952 clarified task logging via log service;
wenzelm
parents: 64170
diff changeset
   155
568cd5123952 clarified task logging via log service;
wenzelm
parents: 64170
diff changeset
   156
  class Task private[Isabelle_Cronjob](name: String, body: => Unit)
568cd5123952 clarified task logging via log service;
wenzelm
parents: 64170
diff changeset
   157
  {
568cd5123952 clarified task logging via log service;
wenzelm
parents: 64170
diff changeset
   158
    private val future: Future[Unit] = Future.thread("cronjob: " + name) { body }
568cd5123952 clarified task logging via log service;
wenzelm
parents: 64170
diff changeset
   159
    def is_finished: Boolean = future.is_finished
64162
03057a8fdd1f simplified: no internal state for Mercurial;
wenzelm
parents: 64157
diff changeset
   160
  }
64153
769791954872 some timing and logging, similar to old isatest.log;
wenzelm
parents: 64148
diff changeset
   161
64170
a0c2cbe2fc8e more explicit management of tasks;
wenzelm
parents: 64162
diff changeset
   162
a0c2cbe2fc8e more explicit management of tasks;
wenzelm
parents: 64162
diff changeset
   163
64153
769791954872 some timing and logging, similar to old isatest.log;
wenzelm
parents: 64148
diff changeset
   164
  /** cronjob **/
769791954872 some timing and logging, similar to old isatest.log;
wenzelm
parents: 64148
diff changeset
   165
64186
49816908ae42 support for separate sub-system options, independent of main Isabelle options;
wenzelm
parents: 64184
diff changeset
   166
  def init_options(): Options = Options.load(Path.explode("~~/Admin/cronjob/cronjob.options"))
49816908ae42 support for separate sub-system options, independent of main Isabelle options;
wenzelm
parents: 64184
diff changeset
   167
64187
450e06dabdd9 allow to exclude named tasks;
wenzelm
parents: 64186
diff changeset
   168
  def cronjob(progress: Progress, exclude_task: Set[String])
64153
769791954872 some timing and logging, similar to old isatest.log;
wenzelm
parents: 64148
diff changeset
   169
  {
64171
568cd5123952 clarified task logging via log service;
wenzelm
parents: 64170
diff changeset
   170
    /* soft lock */
64153
769791954872 some timing and logging, similar to old isatest.log;
wenzelm
parents: 64148
diff changeset
   171
769791954872 some timing and logging, similar to old isatest.log;
wenzelm
parents: 64148
diff changeset
   172
    val still_running =
769791954872 some timing and logging, similar to old isatest.log;
wenzelm
parents: 64148
diff changeset
   173
      try { Some(File.read(main_state_file)) }
769791954872 some timing and logging, similar to old isatest.log;
wenzelm
parents: 64148
diff changeset
   174
      catch { case ERROR(_) => None }
769791954872 some timing and logging, similar to old isatest.log;
wenzelm
parents: 64148
diff changeset
   175
769791954872 some timing and logging, similar to old isatest.log;
wenzelm
parents: 64148
diff changeset
   176
    still_running match {
64170
a0c2cbe2fc8e more explicit management of tasks;
wenzelm
parents: 64162
diff changeset
   177
      case None | Some("") =>
64153
769791954872 some timing and logging, similar to old isatest.log;
wenzelm
parents: 64148
diff changeset
   178
      case Some(running) =>
769791954872 some timing and logging, similar to old isatest.log;
wenzelm
parents: 64148
diff changeset
   179
        error("Isabelle cronjob appears to be still running: " + running)
769791954872 some timing and logging, similar to old isatest.log;
wenzelm
parents: 64148
diff changeset
   180
    }
769791954872 some timing and logging, similar to old isatest.log;
wenzelm
parents: 64148
diff changeset
   181
64199
f38d39c57959 clarified;
wenzelm
parents: 64198
diff changeset
   182
f38d39c57959 clarified;
wenzelm
parents: 64198
diff changeset
   183
    /* log service */
f38d39c57959 clarified;
wenzelm
parents: 64198
diff changeset
   184
64171
568cd5123952 clarified task logging via log service;
wenzelm
parents: 64170
diff changeset
   185
    val log_service = new Log_Service(progress)
64154
e5cf40a54b1e identify managed repository clones;
wenzelm
parents: 64153
diff changeset
   186
64199
f38d39c57959 clarified;
wenzelm
parents: 64198
diff changeset
   187
    def run(start_date: Date, task: Logger_Task) { log_service.run_task(start_date, task) }
f38d39c57959 clarified;
wenzelm
parents: 64198
diff changeset
   188
f38d39c57959 clarified;
wenzelm
parents: 64198
diff changeset
   189
    def run_now(task: Logger_Task) { run(Date.now(), task) }
64154
e5cf40a54b1e identify managed repository clones;
wenzelm
parents: 64153
diff changeset
   190
e5cf40a54b1e identify managed repository clones;
wenzelm
parents: 64153
diff changeset
   191
64199
f38d39c57959 clarified;
wenzelm
parents: 64198
diff changeset
   192
    /* structured tasks */
64184
wenzelm
parents: 64173
diff changeset
   193
64199
f38d39c57959 clarified;
wenzelm
parents: 64198
diff changeset
   194
    def SEQ(tasks: Logger_Task*): Logger_Task = Logger_Task(body = _ =>
64193
7a7e370e2523 clarified log_subdir vs. log_filename;
wenzelm
parents: 64192
diff changeset
   195
      for (task <- tasks.iterator if !exclude_task(task.name) || task.name == "")
64199
f38d39c57959 clarified;
wenzelm
parents: 64198
diff changeset
   196
        run_now(task))
64153
769791954872 some timing and logging, similar to old isatest.log;
wenzelm
parents: 64148
diff changeset
   197
64199
f38d39c57959 clarified;
wenzelm
parents: 64198
diff changeset
   198
    def PAR(tasks: Logger_Task*): Logger_Task = Logger_Task(body = _ =>
64170
a0c2cbe2fc8e more explicit management of tasks;
wenzelm
parents: 64162
diff changeset
   199
      {
64199
f38d39c57959 clarified;
wenzelm
parents: 64198
diff changeset
   200
        @tailrec def join(running: List[Task])
f38d39c57959 clarified;
wenzelm
parents: 64198
diff changeset
   201
        {
f38d39c57959 clarified;
wenzelm
parents: 64198
diff changeset
   202
          running.partition(_.is_finished) match {
f38d39c57959 clarified;
wenzelm
parents: 64198
diff changeset
   203
            case (Nil, Nil) =>
f38d39c57959 clarified;
wenzelm
parents: 64198
diff changeset
   204
            case (Nil, _ :: _) => Thread.sleep(500); join(running)
f38d39c57959 clarified;
wenzelm
parents: 64198
diff changeset
   205
            case (_ :: _, remaining) => join(remaining)
f38d39c57959 clarified;
wenzelm
parents: 64198
diff changeset
   206
          }
64170
a0c2cbe2fc8e more explicit management of tasks;
wenzelm
parents: 64162
diff changeset
   207
        }
64199
f38d39c57959 clarified;
wenzelm
parents: 64198
diff changeset
   208
        val start_date = Date.now()
f38d39c57959 clarified;
wenzelm
parents: 64198
diff changeset
   209
        val running =
f38d39c57959 clarified;
wenzelm
parents: 64198
diff changeset
   210
          for (task <- tasks.toList if !exclude_task(task.name))
f38d39c57959 clarified;
wenzelm
parents: 64198
diff changeset
   211
            yield log_service.fork_task(start_date, task)
f38d39c57959 clarified;
wenzelm
parents: 64198
diff changeset
   212
        join(running)
f38d39c57959 clarified;
wenzelm
parents: 64198
diff changeset
   213
      })
64193
7a7e370e2523 clarified log_subdir vs. log_filename;
wenzelm
parents: 64192
diff changeset
   214
64170
a0c2cbe2fc8e more explicit management of tasks;
wenzelm
parents: 64162
diff changeset
   215
a0c2cbe2fc8e more explicit management of tasks;
wenzelm
parents: 64162
diff changeset
   216
    /* main */
a0c2cbe2fc8e more explicit management of tasks;
wenzelm
parents: 64162
diff changeset
   217
64199
f38d39c57959 clarified;
wenzelm
parents: 64198
diff changeset
   218
    val main_start_date = Date.now()
f38d39c57959 clarified;
wenzelm
parents: 64198
diff changeset
   219
    File.write(main_state_file, main_start_date + " " + log_service.hostname)
f38d39c57959 clarified;
wenzelm
parents: 64198
diff changeset
   220
64193
7a7e370e2523 clarified log_subdir vs. log_filename;
wenzelm
parents: 64192
diff changeset
   221
    run(main_start_date,
7a7e370e2523 clarified log_subdir vs. log_filename;
wenzelm
parents: 64192
diff changeset
   222
      Logger_Task("isabelle_cronjob", _ =>
64215
123e6dcd3852 cronjob: build release from repository snapshot;
wenzelm
parents: 64199
diff changeset
   223
        run_now(SEQ(isabelle_identify, build_history_base, build_release))))
64153
769791954872 some timing and logging, similar to old isatest.log;
wenzelm
parents: 64148
diff changeset
   224
64171
568cd5123952 clarified task logging via log service;
wenzelm
parents: 64170
diff changeset
   225
    log_service.shutdown()
64170
a0c2cbe2fc8e more explicit management of tasks;
wenzelm
parents: 64162
diff changeset
   226
64153
769791954872 some timing and logging, similar to old isatest.log;
wenzelm
parents: 64148
diff changeset
   227
    main_state_file.file.delete
769791954872 some timing and logging, similar to old isatest.log;
wenzelm
parents: 64148
diff changeset
   228
  }
769791954872 some timing and logging, similar to old isatest.log;
wenzelm
parents: 64148
diff changeset
   229
769791954872 some timing and logging, similar to old isatest.log;
wenzelm
parents: 64148
diff changeset
   230
769791954872 some timing and logging, similar to old isatest.log;
wenzelm
parents: 64148
diff changeset
   231
769791954872 some timing and logging, similar to old isatest.log;
wenzelm
parents: 64148
diff changeset
   232
  /** command line entry point **/
769791954872 some timing and logging, similar to old isatest.log;
wenzelm
parents: 64148
diff changeset
   233
64148
bbf43b7c4d0d basic setup for Isabelle cronjob;
wenzelm
parents:
diff changeset
   234
  def main(args: Array[String])
bbf43b7c4d0d basic setup for Isabelle cronjob;
wenzelm
parents:
diff changeset
   235
  {
bbf43b7c4d0d basic setup for Isabelle cronjob;
wenzelm
parents:
diff changeset
   236
    Command_Line.tool0 {
bbf43b7c4d0d basic setup for Isabelle cronjob;
wenzelm
parents:
diff changeset
   237
      var force = false
bbf43b7c4d0d basic setup for Isabelle cronjob;
wenzelm
parents:
diff changeset
   238
      var verbose = false
64187
450e06dabdd9 allow to exclude named tasks;
wenzelm
parents: 64186
diff changeset
   239
      var exclude_task = Set.empty[String]
64148
bbf43b7c4d0d basic setup for Isabelle cronjob;
wenzelm
parents:
diff changeset
   240
bbf43b7c4d0d basic setup for Isabelle cronjob;
wenzelm
parents:
diff changeset
   241
      val getopts = Getopts("""
bbf43b7c4d0d basic setup for Isabelle cronjob;
wenzelm
parents:
diff changeset
   242
Usage: Admin/cronjob/main [OPTIONS]
bbf43b7c4d0d basic setup for Isabelle cronjob;
wenzelm
parents:
diff changeset
   243
bbf43b7c4d0d basic setup for Isabelle cronjob;
wenzelm
parents:
diff changeset
   244
  Options are:
bbf43b7c4d0d basic setup for Isabelle cronjob;
wenzelm
parents:
diff changeset
   245
    -f           apply force to do anything
bbf43b7c4d0d basic setup for Isabelle cronjob;
wenzelm
parents:
diff changeset
   246
    -v           verbose
64187
450e06dabdd9 allow to exclude named tasks;
wenzelm
parents: 64186
diff changeset
   247
    -x NAME      exclude tasks with this name
64148
bbf43b7c4d0d basic setup for Isabelle cronjob;
wenzelm
parents:
diff changeset
   248
""",
bbf43b7c4d0d basic setup for Isabelle cronjob;
wenzelm
parents:
diff changeset
   249
        "f" -> (_ => force = true),
64187
450e06dabdd9 allow to exclude named tasks;
wenzelm
parents: 64186
diff changeset
   250
        "v" -> (_ => verbose = true),
450e06dabdd9 allow to exclude named tasks;
wenzelm
parents: 64186
diff changeset
   251
        "x:" -> (arg => exclude_task += arg))
64148
bbf43b7c4d0d basic setup for Isabelle cronjob;
wenzelm
parents:
diff changeset
   252
bbf43b7c4d0d basic setup for Isabelle cronjob;
wenzelm
parents:
diff changeset
   253
      val more_args = getopts(args)
bbf43b7c4d0d basic setup for Isabelle cronjob;
wenzelm
parents:
diff changeset
   254
      if (more_args.nonEmpty) getopts.usage()
bbf43b7c4d0d basic setup for Isabelle cronjob;
wenzelm
parents:
diff changeset
   255
64153
769791954872 some timing and logging, similar to old isatest.log;
wenzelm
parents: 64148
diff changeset
   256
      val progress = if (verbose) new Console_Progress() else Ignore_Progress
64148
bbf43b7c4d0d basic setup for Isabelle cronjob;
wenzelm
parents:
diff changeset
   257
64187
450e06dabdd9 allow to exclude named tasks;
wenzelm
parents: 64186
diff changeset
   258
      if (force) cronjob(progress, exclude_task)
64153
769791954872 some timing and logging, similar to old isatest.log;
wenzelm
parents: 64148
diff changeset
   259
      else error("Need to apply force to do anything")
64148
bbf43b7c4d0d basic setup for Isabelle cronjob;
wenzelm
parents:
diff changeset
   260
    }
bbf43b7c4d0d basic setup for Isabelle cronjob;
wenzelm
parents:
diff changeset
   261
  }
bbf43b7c4d0d basic setup for Isabelle cronjob;
wenzelm
parents:
diff changeset
   262
}