author | wenzelm |
Sat, 29 Apr 2017 21:04:03 +0200 | |
changeset 65640 | 7a26c337e016 |
parent 65594 | 659305708959 |
child 65647 | 7cf60e2b9115 |
permissions | -rw-r--r-- |
64148 | 1 |
/* Title: Pure/Admin/isabelle_cronjob.scala |
2 |
Author: Makarius |
|
3 |
||
4 |
Main entry point for administrative cronjob at TUM. |
|
5 |
*/ |
|
6 |
||
7 |
package isabelle |
|
8 |
||
9 |
||
64170 | 10 |
import scala.annotation.tailrec |
11 |
import scala.collection.mutable |
|
12 |
||
13 |
||
64148 | 14 |
object Isabelle_Cronjob |
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 | 20 |
val current_log = main_dir + Path.explode("run/main.log") // owned by log service |
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 |
|
64231
dbc8294c75d3
added remote_build_history tasks: parallel on several remote hosts;
wenzelm
parents:
64220
diff
changeset
|
23 |
val isabelle_repos = main_dir + Path.explode("isabelle") |
dbc8294c75d3
added remote_build_history tasks: parallel on several remote hosts;
wenzelm
parents:
64220
diff
changeset
|
24 |
val isabelle_repos_test = main_dir + Path.explode("isabelle-test") |
dbc8294c75d3
added remote_build_history tasks: parallel on several remote hosts;
wenzelm
parents:
64220
diff
changeset
|
25 |
val afp_repos = main_dir + Path.explode("AFP") |
64153
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
26 |
|
64236
358f9ff08681
discontinued somewhat pointless cronjob.options -- compile-time constants are sufficient;
wenzelm
parents:
64235
diff
changeset
|
27 |
val isabelle_dev_source = "http://isabelle.in.tum.de/repos/isabelle" |
358f9ff08681
discontinued somewhat pointless cronjob.options -- compile-time constants are sufficient;
wenzelm
parents:
64235
diff
changeset
|
28 |
val isabelle_release_source = "http://bitbucket.org/isabelle_project/isabelle-release" |
358f9ff08681
discontinued somewhat pointless cronjob.options -- compile-time constants are sufficient;
wenzelm
parents:
64235
diff
changeset
|
29 |
val afp_source = "https://bitbucket.org/isa-afp/afp-devel" |
358f9ff08681
discontinued somewhat pointless cronjob.options -- compile-time constants are sufficient;
wenzelm
parents:
64235
diff
changeset
|
30 |
|
64218 | 31 |
val release_snapshot = Path.explode("~/html-data/release_snapshot") |
64215 | 32 |
|
64153
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
33 |
|
64192 | 34 |
|
35 |
/** particular tasks **/ |
|
36 |
||
64405
81bac77929d9
just one task to identify Isabelle + AFP repository snapshots and build release;
wenzelm
parents:
64399
diff
changeset
|
37 |
/* identify Isabelle + AFP repository snapshots and build release */ |
64192 | 38 |
|
64405
81bac77929d9
just one task to identify Isabelle + AFP repository snapshots and build release;
wenzelm
parents:
64399
diff
changeset
|
39 |
private val build_release = |
81bac77929d9
just one task to identify Isabelle + AFP repository snapshots and build release;
wenzelm
parents:
64399
diff
changeset
|
40 |
Logger_Task("build_release", logger => |
81bac77929d9
just one task to identify Isabelle + AFP repository snapshots and build release;
wenzelm
parents:
64399
diff
changeset
|
41 |
Isabelle_System.with_tmp_dir("isadist")(base_dir => |
81bac77929d9
just one task to identify Isabelle + AFP repository snapshots and build release;
wenzelm
parents:
64399
diff
changeset
|
42 |
{ |
81bac77929d9
just one task to identify Isabelle + AFP repository snapshots and build release;
wenzelm
parents:
64399
diff
changeset
|
43 |
val rev = Mercurial.repository(isabelle_repos).id() |
81bac77929d9
just one task to identify Isabelle + AFP repository snapshots and build release;
wenzelm
parents:
64399
diff
changeset
|
44 |
val afp_rev = Mercurial.setup_repository(afp_source, afp_repos).id() |
64192 | 45 |
|
64405
81bac77929d9
just one task to identify Isabelle + AFP repository snapshots and build release;
wenzelm
parents:
64399
diff
changeset
|
46 |
File.write(logger.log_dir + Build_Log.log_filename("isabelle_identify", logger.start_date), |
81bac77929d9
just one task to identify Isabelle + AFP repository snapshots and build release;
wenzelm
parents:
64399
diff
changeset
|
47 |
terminate_lines( |
81bac77929d9
just one task to identify Isabelle + AFP repository snapshots and build release;
wenzelm
parents:
64399
diff
changeset
|
48 |
List("isabelle_identify: " + Build_Log.print_date(logger.start_date), |
81bac77929d9
just one task to identify Isabelle + AFP repository snapshots and build release;
wenzelm
parents:
64399
diff
changeset
|
49 |
"", |
81bac77929d9
just one task to identify Isabelle + AFP repository snapshots and build release;
wenzelm
parents:
64399
diff
changeset
|
50 |
"Isabelle version: " + rev, |
81bac77929d9
just one task to identify Isabelle + AFP repository snapshots and build release;
wenzelm
parents:
64399
diff
changeset
|
51 |
"AFP version: " + afp_rev))) |
81bac77929d9
just one task to identify Isabelle + AFP repository snapshots and build release;
wenzelm
parents:
64399
diff
changeset
|
52 |
|
81bac77929d9
just one task to identify Isabelle + AFP repository snapshots and build release;
wenzelm
parents:
64399
diff
changeset
|
53 |
val new_snapshot = release_snapshot.ext("new") |
81bac77929d9
just one task to identify Isabelle + AFP repository snapshots and build release;
wenzelm
parents:
64399
diff
changeset
|
54 |
val old_snapshot = release_snapshot.ext("old") |
81bac77929d9
just one task to identify Isabelle + AFP repository snapshots and build release;
wenzelm
parents:
64399
diff
changeset
|
55 |
|
81bac77929d9
just one task to identify Isabelle + AFP repository snapshots and build release;
wenzelm
parents:
64399
diff
changeset
|
56 |
Isabelle_System.rm_tree(new_snapshot) |
81bac77929d9
just one task to identify Isabelle + AFP repository snapshots and build release;
wenzelm
parents:
64399
diff
changeset
|
57 |
Isabelle_System.rm_tree(old_snapshot) |
81bac77929d9
just one task to identify Isabelle + AFP repository snapshots and build release;
wenzelm
parents:
64399
diff
changeset
|
58 |
|
81bac77929d9
just one task to identify Isabelle + AFP repository snapshots and build release;
wenzelm
parents:
64399
diff
changeset
|
59 |
Build_Release.build_release(base_dir, rev = rev, afp_rev = afp_rev, |
81bac77929d9
just one task to identify Isabelle + AFP repository snapshots and build release;
wenzelm
parents:
64399
diff
changeset
|
60 |
parallel_jobs = 4, remote_mac = "macbroy31", website = Some(new_snapshot)) |
81bac77929d9
just one task to identify Isabelle + AFP repository snapshots and build release;
wenzelm
parents:
64399
diff
changeset
|
61 |
|
64482
43f6c28ff496
clarified File.move: target directory like File.copy;
wenzelm
parents:
64481
diff
changeset
|
62 |
if (release_snapshot.is_dir) File.move(release_snapshot, old_snapshot) |
43f6c28ff496
clarified File.move: target directory like File.copy;
wenzelm
parents:
64481
diff
changeset
|
63 |
File.move(new_snapshot, release_snapshot) |
64405
81bac77929d9
just one task to identify Isabelle + AFP repository snapshots and build release;
wenzelm
parents:
64399
diff
changeset
|
64 |
Isabelle_System.rm_tree(old_snapshot) |
81bac77929d9
just one task to identify Isabelle + AFP repository snapshots and build release;
wenzelm
parents:
64399
diff
changeset
|
65 |
})) |
64192 | 66 |
|
67 |
||
64194
b5ada7dcceaa
integrity test of build_history vs. build_history_base;
wenzelm
parents:
64193
diff
changeset
|
68 |
/* integrity test of build_history vs. build_history_base */ |
64193 | 69 |
|
64194
b5ada7dcceaa
integrity test of build_history vs. build_history_base;
wenzelm
parents:
64193
diff
changeset
|
70 |
private val build_history_base = |
64193 | 71 |
Logger_Task("build_history_base", logger => |
72 |
{ |
|
64251 | 73 |
val hg = |
74 |
Mercurial.setup_repository( |
|
75 |
File.standard_path(isabelle_repos), isabelle_repos_test) |
|
64194
b5ada7dcceaa
integrity test of build_history vs. build_history_base;
wenzelm
parents:
64193
diff
changeset
|
76 |
for { |
b5ada7dcceaa
integrity test of build_history vs. build_history_base;
wenzelm
parents:
64193
diff
changeset
|
77 |
(result, log_path) <- |
64251 | 78 |
Build_History.build_history( |
79 |
hg, rev = "build_history_base", fresh = true, build_args = List("HOL")) |
|
64194
b5ada7dcceaa
integrity test of build_history vs. build_history_base;
wenzelm
parents:
64193
diff
changeset
|
80 |
} { |
b5ada7dcceaa
integrity test of build_history vs. build_history_base;
wenzelm
parents:
64193
diff
changeset
|
81 |
result.check |
64482
43f6c28ff496
clarified File.move: target directory like File.copy;
wenzelm
parents:
64481
diff
changeset
|
82 |
File.move(log_path, logger.log_dir + log_path.base) |
64194
b5ada7dcceaa
integrity test of build_history vs. build_history_base;
wenzelm
parents:
64193
diff
changeset
|
83 |
} |
64193 | 84 |
}) |
85 |
||
86 |
||
64231
dbc8294c75d3
added remote_build_history tasks: parallel on several remote hosts;
wenzelm
parents:
64220
diff
changeset
|
87 |
/* remote build_history */ |
dbc8294c75d3
added remote_build_history tasks: parallel on several remote hosts;
wenzelm
parents:
64220
diff
changeset
|
88 |
|
64409
70c87ca55f2c
tuned signature -- more friendly for experimentation;
wenzelm
parents:
64405
diff
changeset
|
89 |
sealed case class Remote_Build( |
64231
dbc8294c75d3
added remote_build_history tasks: parallel on several remote hosts;
wenzelm
parents:
64220
diff
changeset
|
90 |
host: String, |
dbc8294c75d3
added remote_build_history tasks: parallel on several remote hosts;
wenzelm
parents:
64220
diff
changeset
|
91 |
user: String = "", |
65594 | 92 |
port: Int = 0, |
64294
303976a45afe
shared_home is default for classic isatest home setup;
wenzelm
parents:
64277
diff
changeset
|
93 |
shared_home: Boolean = true, |
64231
dbc8294c75d3
added remote_build_history tasks: parallel on several remote hosts;
wenzelm
parents:
64220
diff
changeset
|
94 |
options: String = "", |
64351 | 95 |
args: String = "") |
64231
dbc8294c75d3
added remote_build_history tasks: parallel on several remote hosts;
wenzelm
parents:
64220
diff
changeset
|
96 |
|
dbc8294c75d3
added remote_build_history tasks: parallel on several remote hosts;
wenzelm
parents:
64220
diff
changeset
|
97 |
private val remote_builds = |
dbc8294c75d3
added remote_build_history tasks: parallel on several remote hosts;
wenzelm
parents:
64220
diff
changeset
|
98 |
List( |
65063 | 99 |
List(Remote_Build("lxbroy8", |
100 |
options = "-m32 -B -M1x2,2 -t polyml-test -e 'init_component /home/isabelle/contrib/polyml-5.7-20170217'", |
|
101 |
args = "-N -g timing")), |
|
64506
b3ccfd59097d
more cronjob tasks, using Poly/ML repository version from 13-Nov-2016;
wenzelm
parents:
64482
diff
changeset
|
102 |
List(Remote_Build("lxbroy9", options = "-m32 -B -M1x2,2", args = "-N -g timing")), |
64476
62c807eb009f
proper option for "build", not "build_history" (cf. 5ca4ac099e94);
wenzelm
parents:
64468
diff
changeset
|
103 |
List(Remote_Build("lxbroy10", options = "-m32 -B -M1x4,2,4,6", args = "-N -g timing")), |
64351 | 104 |
List( |
105 |
Remote_Build("macbroy2", options = "-m32 -M8", args = "-a"), |
|
106 |
Remote_Build("macbroy2", options = "-m32 -M8 -t quick_and_dirty", args = "-a -o quick_and_dirty"), |
|
107 |
Remote_Build("macbroy2", options = "-m32 -M8 -t skip_proofs", args = "-a -o skip_proofs")), |
|
108 |
List(Remote_Build("macbroy30", options = "-m32 -M2", args = "-a")), |
|
109 |
List(Remote_Build("macbroy31", options = "-m32 -M2", args = "-a")), |
|
110 |
List( |
|
111 |
Remote_Build("vmnipkow9", shared_home = false, options = "-m32 -M4", args = "-a"), |
|
112 |
Remote_Build("vmnipkow9", shared_home = false, options = "-m64 -M4", args = "-a"))) |
|
64231
dbc8294c75d3
added remote_build_history tasks: parallel on several remote hosts;
wenzelm
parents:
64220
diff
changeset
|
113 |
|
dbc8294c75d3
added remote_build_history tasks: parallel on several remote hosts;
wenzelm
parents:
64220
diff
changeset
|
114 |
private def remote_build_history(rev: String, r: Remote_Build): Logger_Task = |
64294
303976a45afe
shared_home is default for classic isatest home setup;
wenzelm
parents:
64277
diff
changeset
|
115 |
{ |
303976a45afe
shared_home is default for classic isatest home setup;
wenzelm
parents:
64277
diff
changeset
|
116 |
val task_name = "build_history-" + r.host |
303976a45afe
shared_home is default for classic isatest home setup;
wenzelm
parents:
64277
diff
changeset
|
117 |
Logger_Task(task_name, logger => |
64231
dbc8294c75d3
added remote_build_history tasks: parallel on several remote hosts;
wenzelm
parents:
64220
diff
changeset
|
118 |
{ |
dbc8294c75d3
added remote_build_history tasks: parallel on several remote hosts;
wenzelm
parents:
64220
diff
changeset
|
119 |
using(logger.ssh_context.open_session(host = r.host, user = r.user, port = r.port))( |
64259 | 120 |
ssh => |
64231
dbc8294c75d3
added remote_build_history tasks: parallel on several remote hosts;
wenzelm
parents:
64220
diff
changeset
|
121 |
{ |
64348
4c253e84ae62
clarified push/pull chain: current ISABELLE_HOME may server as source for changes that are not published on isabelle_repos_source yet (e.g. isabelle-release branch);
wenzelm
parents:
64346
diff
changeset
|
122 |
val self_update = !r.shared_home |
4c253e84ae62
clarified push/pull chain: current ISABELLE_HOME may server as source for changes that are not published on isabelle_repos_source yet (e.g. isabelle-release branch);
wenzelm
parents:
64346
diff
changeset
|
123 |
val push_isabelle_home = self_update && Mercurial.is_repository(Path.explode("~~")) |
4c253e84ae62
clarified push/pull chain: current ISABELLE_HOME may server as source for changes that are not published on isabelle_repos_source yet (e.g. isabelle-release branch);
wenzelm
parents:
64346
diff
changeset
|
124 |
|
64468
ed8940d6295c
back to more elementary result (see 5f49765a25ec): avoid concurrent use of ssh channel;
wenzelm
parents:
64452
diff
changeset
|
125 |
val (results, _) = |
ed8940d6295c
back to more elementary result (see 5f49765a25ec): avoid concurrent use of ssh channel;
wenzelm
parents:
64452
diff
changeset
|
126 |
Build_History.remote_build_history(ssh, |
ed8940d6295c
back to more elementary result (see 5f49765a25ec): avoid concurrent use of ssh channel;
wenzelm
parents:
64452
diff
changeset
|
127 |
isabelle_repos, |
ed8940d6295c
back to more elementary result (see 5f49765a25ec): avoid concurrent use of ssh channel;
wenzelm
parents:
64452
diff
changeset
|
128 |
isabelle_repos.ext(r.host), |
64538 | 129 |
isabelle_repos_source = isabelle_dev_source, |
64468
ed8940d6295c
back to more elementary result (see 5f49765a25ec): avoid concurrent use of ssh channel;
wenzelm
parents:
64452
diff
changeset
|
130 |
self_update = self_update, |
ed8940d6295c
back to more elementary result (see 5f49765a25ec): avoid concurrent use of ssh channel;
wenzelm
parents:
64452
diff
changeset
|
131 |
push_isabelle_home = push_isabelle_home, |
ed8940d6295c
back to more elementary result (see 5f49765a25ec): avoid concurrent use of ssh channel;
wenzelm
parents:
64452
diff
changeset
|
132 |
options = |
64479 | 133 |
"-r " + Bash.string(rev) + " -N " + Bash.string(task_name) + " -f " + r.options, |
64468
ed8940d6295c
back to more elementary result (see 5f49765a25ec): avoid concurrent use of ssh channel;
wenzelm
parents:
64452
diff
changeset
|
134 |
args = "-o timeout=10800 " + r.args) |
64346 | 135 |
|
64481 | 136 |
for ((log_name, bytes) <- results) { |
137 |
logger.log(Date.now(), log_name) |
|
64468
ed8940d6295c
back to more elementary result (see 5f49765a25ec): avoid concurrent use of ssh channel;
wenzelm
parents:
64452
diff
changeset
|
138 |
Bytes.write(logger.log_dir + Path.explode(log_name), bytes) |
64481 | 139 |
} |
64231
dbc8294c75d3
added remote_build_history tasks: parallel on several remote hosts;
wenzelm
parents:
64220
diff
changeset
|
140 |
}) |
dbc8294c75d3
added remote_build_history tasks: parallel on several remote hosts;
wenzelm
parents:
64220
diff
changeset
|
141 |
}) |
64294
303976a45afe
shared_home is default for classic isatest home setup;
wenzelm
parents:
64277
diff
changeset
|
142 |
} |
64231
dbc8294c75d3
added remote_build_history tasks: parallel on several remote hosts;
wenzelm
parents:
64220
diff
changeset
|
143 |
|
dbc8294c75d3
added remote_build_history tasks: parallel on several remote hosts;
wenzelm
parents:
64220
diff
changeset
|
144 |
|
65640 | 145 |
/* maintain build_log database */ |
146 |
||
147 |
val database_dirs = |
|
148 |
List(Path.explode("~/log"), Path.explode("~/afp/log"), Path.explode("~/cronjob/log")) |
|
149 |
||
150 |
def database_update(options: Options) |
|
151 |
{ |
|
152 |
val store = Build_Log.store(options) |
|
153 |
using(store.open_database())(db => |
|
154 |
store.write_info(db, Build_Log.Log_File.find_files(database_dirs))) |
|
155 |
} |
|
156 |
||
157 |
||
64192 | 158 |
|
159 |
/** task logging **/ |
|
64171 | 160 |
|
64193 | 161 |
sealed case class Logger_Task(name: String = "", body: Logger => Unit) |
64154 | 162 |
|
64257 | 163 |
class Log_Service private[Isabelle_Cronjob](progress: Progress, val ssh_context: SSH.Context) |
64171 | 164 |
{ |
64219 | 165 |
current_log.file.delete |
166 |
||
64171 | 167 |
private val thread: Consumer_Thread[String] = |
168 |
Consumer_Thread.fork("cronjob: logger", daemon = true)( |
|
169 |
consume = (text: String) => |
|
64219 | 170 |
{ // critical |
171 |
File.append(current_log, text + "\n") |
|
172 |
File.append(cumulative_log, text + "\n") |
|
64171 | 173 |
progress.echo(text) |
174 |
true |
|
175 |
}) |
|
176 |
||
177 |
def shutdown() { thread.shutdown() } |
|
178 |
||
179 |
val hostname = Isabelle_System.hostname() |
|
180 |
||
181 |
def log(date: Date, task_name: String, msg: String): Unit = |
|
64193 | 182 |
if (task_name != "") |
183 |
thread.send( |
|
184 |
"[" + Build_Log.print_date(date) + ", " + hostname + ", " + task_name + "]: " + msg) |
|
64171 | 185 |
|
186 |
def start_logger(start_date: Date, task_name: String): Logger = |
|
187 |
new Logger(this, start_date, task_name) |
|
64154 | 188 |
|
64171 | 189 |
def run_task(start_date: Date, task: Logger_Task) |
190 |
{ |
|
191 |
val logger = start_logger(start_date, task.name) |
|
192 |
val res = Exn.capture { task.body(logger) } |
|
193 |
val end_date = Date.now() |
|
194 |
val err = |
|
195 |
res match { |
|
196 |
case Exn.Res(_) => None |
|
64295 | 197 |
case Exn.Exn(exn) => |
64410 | 198 |
System.err.println("Exception trace for " + quote(task.name) + ":") |
64397 | 199 |
exn.printStackTrace() |
64295 | 200 |
val first_line = Library.split_lines(Exn.message(exn)).headOption getOrElse "exception" |
201 |
Some(first_line) |
|
64171 | 202 |
} |
203 |
logger.log_end(end_date, err) |
|
204 |
} |
|
205 |
||
206 |
def fork_task(start_date: Date, task: Logger_Task): Task = |
|
207 |
new Task(task.name, run_task(start_date, task)) |
|
208 |
} |
|
209 |
||
210 |
class Logger private[Isabelle_Cronjob]( |
|
211 |
val log_service: Log_Service, val start_date: Date, val task_name: String) |
|
64162 | 212 |
{ |
64257 | 213 |
def ssh_context: SSH.Context = log_service.ssh_context |
65640 | 214 |
def options: Options = ssh_context.options |
64231
dbc8294c75d3
added remote_build_history tasks: parallel on several remote hosts;
wenzelm
parents:
64220
diff
changeset
|
215 |
|
64171 | 216 |
def log(date: Date, msg: String): Unit = log_service.log(date, task_name, msg) |
217 |
||
218 |
def log_end(end_date: Date, err: Option[String]) |
|
219 |
{ |
|
220 |
val elapsed_time = end_date.time - start_date.time |
|
221 |
val msg = |
|
222 |
(if (err.isEmpty) "finished" else "ERROR " + err.get) + |
|
64197 | 223 |
(if (elapsed_time.seconds < 3.0) "" else " (" + elapsed_time.message_hms + " elapsed time)") |
64171 | 224 |
log(end_date, msg) |
225 |
} |
|
226 |
||
64195 | 227 |
val log_dir: Path = main_dir + Build_Log.log_subdir(start_date) |
228 |
||
229 |
Isabelle_System.mkdirs(log_dir) |
|
64171 | 230 |
log(start_date, "started") |
231 |
} |
|
232 |
||
233 |
class Task private[Isabelle_Cronjob](name: String, body: => Unit) |
|
234 |
{ |
|
235 |
private val future: Future[Unit] = Future.thread("cronjob: " + name) { body } |
|
236 |
def is_finished: Boolean = future.is_finished |
|
64162 | 237 |
} |
64153
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
238 |
|
64170 | 239 |
|
240 |
||
64153
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
241 |
/** cronjob **/ |
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
242 |
|
64187 | 243 |
def cronjob(progress: Progress, exclude_task: Set[String]) |
64153
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
244 |
{ |
64171 | 245 |
/* soft lock */ |
64153
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
246 |
|
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
247 |
val still_running = |
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
248 |
try { Some(File.read(main_state_file)) } |
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
249 |
catch { case ERROR(_) => None } |
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
250 |
|
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
251 |
still_running match { |
64170 | 252 |
case None | Some("") => |
64153
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
253 |
case Some(running) => |
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
254 |
error("Isabelle cronjob appears to be still running: " + running) |
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
255 |
} |
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
256 |
|
64199 | 257 |
|
258 |
/* log service */ |
|
259 |
||
64257 | 260 |
val log_service = new Log_Service(progress, SSH.init_context(Options.init())) |
64154 | 261 |
|
64199 | 262 |
def run(start_date: Date, task: Logger_Task) { log_service.run_task(start_date, task) } |
263 |
||
264 |
def run_now(task: Logger_Task) { run(Date.now(), task) } |
|
64154 | 265 |
|
266 |
||
64199 | 267 |
/* structured tasks */ |
64184 | 268 |
|
64350
3af8566788e7
remote_builds has PAR-SEQ semantics of old isatest-makedist;
wenzelm
parents:
64348
diff
changeset
|
269 |
def SEQ(tasks: List[Logger_Task]): Logger_Task = Logger_Task(body = _ => |
64193 | 270 |
for (task <- tasks.iterator if !exclude_task(task.name) || task.name == "") |
64199 | 271 |
run_now(task)) |
64153
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
272 |
|
64350
3af8566788e7
remote_builds has PAR-SEQ semantics of old isatest-makedist;
wenzelm
parents:
64348
diff
changeset
|
273 |
def PAR(tasks: List[Logger_Task]): Logger_Task = Logger_Task(body = _ => |
64170 | 274 |
{ |
64199 | 275 |
@tailrec def join(running: List[Task]) |
276 |
{ |
|
277 |
running.partition(_.is_finished) match { |
|
278 |
case (Nil, Nil) => |
|
279 |
case (Nil, _ :: _) => Thread.sleep(500); join(running) |
|
280 |
case (_ :: _, remaining) => join(remaining) |
|
281 |
} |
|
64170 | 282 |
} |
64199 | 283 |
val start_date = Date.now() |
284 |
val running = |
|
64350
3af8566788e7
remote_builds has PAR-SEQ semantics of old isatest-makedist;
wenzelm
parents:
64348
diff
changeset
|
285 |
for (task <- tasks if !exclude_task(task.name)) |
64199 | 286 |
yield log_service.fork_task(start_date, task) |
287 |
join(running) |
|
288 |
}) |
|
64193 | 289 |
|
64170 | 290 |
|
291 |
/* main */ |
|
292 |
||
64199 | 293 |
val main_start_date = Date.now() |
294 |
File.write(main_state_file, main_start_date + " " + log_service.hostname) |
|
295 |
||
64232
367d83d6030e
clarified hg.id operation, with explicit tip as default;
wenzelm
parents:
64231
diff
changeset
|
296 |
val rev = Mercurial.repository(isabelle_repos).id() |
64231
dbc8294c75d3
added remote_build_history tasks: parallel on several remote hosts;
wenzelm
parents:
64220
diff
changeset
|
297 |
|
64193 | 298 |
run(main_start_date, |
299 |
Logger_Task("isabelle_cronjob", _ => |
|
64231
dbc8294c75d3
added remote_build_history tasks: parallel on several remote hosts;
wenzelm
parents:
64220
diff
changeset
|
300 |
run_now( |
64405
81bac77929d9
just one task to identify Isabelle + AFP repository snapshots and build release;
wenzelm
parents:
64399
diff
changeset
|
301 |
SEQ(List(build_release, build_history_base, |
65640 | 302 |
PAR(remote_builds.map(seq => SEQ(seq.map(remote_build_history(rev, _))))), |
303 |
Logger_Task("build_log_database", logger => database_update(logger.options))))))) |
|
64153
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
304 |
|
64171 | 305 |
log_service.shutdown() |
64170 | 306 |
|
64153
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
307 |
main_state_file.file.delete |
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
308 |
} |
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
309 |
|
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
310 |
|
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
311 |
|
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
312 |
/** command line entry point **/ |
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
313 |
|
64148 | 314 |
def main(args: Array[String]) |
315 |
{ |
|
316 |
Command_Line.tool0 { |
|
317 |
var force = false |
|
318 |
var verbose = false |
|
64187 | 319 |
var exclude_task = Set.empty[String] |
64148 | 320 |
|
321 |
val getopts = Getopts(""" |
|
322 |
Usage: Admin/cronjob/main [OPTIONS] |
|
323 |
||
324 |
Options are: |
|
325 |
-f apply force to do anything |
|
326 |
-v verbose |
|
64187 | 327 |
-x NAME exclude tasks with this name |
64148 | 328 |
""", |
329 |
"f" -> (_ => force = true), |
|
64187 | 330 |
"v" -> (_ => verbose = true), |
331 |
"x:" -> (arg => exclude_task += arg)) |
|
64148 | 332 |
|
333 |
val more_args = getopts(args) |
|
334 |
if (more_args.nonEmpty) getopts.usage() |
|
335 |
||
64909 | 336 |
val progress = if (verbose) new Console_Progress() else No_Progress |
64148 | 337 |
|
64187 | 338 |
if (force) cronjob(progress, exclude_task) |
64153
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
339 |
else error("Need to apply force to do anything") |
64148 | 340 |
} |
341 |
} |
|
342 |
} |