author | wenzelm |
Fri, 12 May 2017 16:24:29 +0200 | |
changeset 65809 | 8d5ac49388ea |
parent 65808 | cb3e9d7f1d5f |
child 65810 | 356c2b488cf3 |
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 |
|
65736 | 31 |
val jenkins_jobs = "identify" :: Jenkins.build_log_jobs |
65666
45d0692bb019
incremental download of Jenkins log files, which are also added to database;
wenzelm
parents:
65647
diff
changeset
|
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 |
{ |
65771 | 42 |
Isabelle_Devel.make_index() |
43 |
||
64405
81bac77929d9
just one task to identify Isabelle + AFP repository snapshots and build release;
wenzelm
parents:
64399
diff
changeset
|
44 |
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
|
45 |
val afp_rev = Mercurial.setup_repository(afp_source, afp_repos).id() |
64192 | 46 |
|
64405
81bac77929d9
just one task to identify Isabelle + AFP repository snapshots and build release;
wenzelm
parents:
64399
diff
changeset
|
47 |
File.write(logger.log_dir + Build_Log.log_filename("isabelle_identify", logger.start_date), |
65674
23897f5d885d
approximate repository identify job based on isabelle-nightly-slow;
wenzelm
parents:
65670
diff
changeset
|
48 |
Build_Log.Identify.content(logger.start_date, Some(rev), Some(afp_rev))) |
64405
81bac77929d9
just one task to identify Isabelle + AFP repository snapshots and build release;
wenzelm
parents:
64399
diff
changeset
|
49 |
|
65770 | 50 |
Isabelle_Devel.release_snapshot(rev = rev, afp_rev = afp_rev, |
51 |
parallel_jobs = 4, remote_mac = "macbroy31") |
|
52 |
}) |
|
64192 | 53 |
|
54 |
||
64194
b5ada7dcceaa
integrity test of build_history vs. build_history_base;
wenzelm
parents:
64193
diff
changeset
|
55 |
/* integrity test of build_history vs. build_history_base */ |
64193 | 56 |
|
64194
b5ada7dcceaa
integrity test of build_history vs. build_history_base;
wenzelm
parents:
64193
diff
changeset
|
57 |
private val build_history_base = |
64193 | 58 |
Logger_Task("build_history_base", logger => |
59 |
{ |
|
64251 | 60 |
val hg = |
61 |
Mercurial.setup_repository( |
|
62 |
File.standard_path(isabelle_repos), isabelle_repos_test) |
|
64194
b5ada7dcceaa
integrity test of build_history vs. build_history_base;
wenzelm
parents:
64193
diff
changeset
|
63 |
for { |
b5ada7dcceaa
integrity test of build_history vs. build_history_base;
wenzelm
parents:
64193
diff
changeset
|
64 |
(result, log_path) <- |
64251 | 65 |
Build_History.build_history( |
66 |
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
|
67 |
} { |
b5ada7dcceaa
integrity test of build_history vs. build_history_base;
wenzelm
parents:
64193
diff
changeset
|
68 |
result.check |
64482
43f6c28ff496
clarified File.move: target directory like File.copy;
wenzelm
parents:
64481
diff
changeset
|
69 |
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
|
70 |
} |
64193 | 71 |
}) |
72 |
||
73 |
||
64231
dbc8294c75d3
added remote_build_history tasks: parallel on several remote hosts;
wenzelm
parents:
64220
diff
changeset
|
74 |
/* remote build_history */ |
dbc8294c75d3
added remote_build_history tasks: parallel on several remote hosts;
wenzelm
parents:
64220
diff
changeset
|
75 |
|
65783
d3d5cb2d6866
pick isabelle_version based on build_log database;
wenzelm
parents:
65771
diff
changeset
|
76 |
sealed case class Item(known: Boolean, isabelle_version: String, pull_date: Date) |
d3d5cb2d6866
pick isabelle_version based on build_log database;
wenzelm
parents:
65771
diff
changeset
|
77 |
{ |
d3d5cb2d6866
pick isabelle_version based on build_log database;
wenzelm
parents:
65771
diff
changeset
|
78 |
def unknown: Boolean = !known |
d3d5cb2d6866
pick isabelle_version based on build_log database;
wenzelm
parents:
65771
diff
changeset
|
79 |
} |
d3d5cb2d6866
pick isabelle_version based on build_log database;
wenzelm
parents:
65771
diff
changeset
|
80 |
|
65807 | 81 |
def recent_items(db: SQL.Database, days: Int, rev: String, sql: SQL.Source): List[Item] = |
82 |
{ |
|
83 |
val select = |
|
84 |
Build_Log.Data.select_recent_isabelle_versions(days = days, rev = rev, sql = "WHERE " + sql) |
|
85 |
||
86 |
db.using_statement(select)(stmt => |
|
87 |
stmt.execute_query().iterator(res => |
|
88 |
{ |
|
89 |
val known = res.bool(Build_Log.Data.known) |
|
90 |
val isabelle_version = res.string(Build_Log.Prop.isabelle_version) |
|
91 |
val pull_date = res.date(Build_Log.Data.pull_date) |
|
92 |
Item(known, isabelle_version, pull_date) |
|
93 |
}).toList) |
|
94 |
} |
|
95 |
||
96 |
def unknown_runs(items: List[Item]): List[List[Item]] = |
|
97 |
{ |
|
98 |
val (run, rest) = Library.take_prefix[Item](_.unknown, items.dropWhile(_.known)) |
|
99 |
if (run.nonEmpty) run :: unknown_runs(rest) else Nil |
|
100 |
} |
|
101 |
||
64409
70c87ca55f2c
tuned signature -- more friendly for experimentation;
wenzelm
parents:
64405
diff
changeset
|
102 |
sealed case class Remote_Build( |
65764 | 103 |
description: String, |
64231
dbc8294c75d3
added remote_build_history tasks: parallel on several remote hosts;
wenzelm
parents:
64220
diff
changeset
|
104 |
host: String, |
dbc8294c75d3
added remote_build_history tasks: parallel on several remote hosts;
wenzelm
parents:
64220
diff
changeset
|
105 |
user: String = "", |
65594 | 106 |
port: Int = 0, |
64294
303976a45afe
shared_home is default for classic isatest home setup;
wenzelm
parents:
64277
diff
changeset
|
107 |
shared_home: Boolean = true, |
65789 | 108 |
history: Int = 0, |
65809 | 109 |
historic: Boolean = false, |
64231
dbc8294c75d3
added remote_build_history tasks: parallel on several remote hosts;
wenzelm
parents:
64220
diff
changeset
|
110 |
options: String = "", |
65732 | 111 |
args: String = "", |
112 |
detect: SQL.Source = "") |
|
113 |
{ |
|
65783
d3d5cb2d6866
pick isabelle_version based on build_log database;
wenzelm
parents:
65771
diff
changeset
|
114 |
def sql: SQL.Source = |
d3d5cb2d6866
pick isabelle_version based on build_log database;
wenzelm
parents:
65771
diff
changeset
|
115 |
Build_Log.Prop.build_engine + " = " + SQL.string(Build_History.engine) + " AND " + |
d3d5cb2d6866
pick isabelle_version based on build_log database;
wenzelm
parents:
65771
diff
changeset
|
116 |
Build_Log.Prop.build_host + " = " + SQL.string(host) + |
d3d5cb2d6866
pick isabelle_version based on build_log database;
wenzelm
parents:
65771
diff
changeset
|
117 |
(if (detect == "") "" else " AND " + SQL.enclose(detect)) |
d3d5cb2d6866
pick isabelle_version based on build_log database;
wenzelm
parents:
65771
diff
changeset
|
118 |
|
65747 | 119 |
def profile: Build_Status.Profile = |
65798 | 120 |
Build_Status.Profile(description, history, sql) |
65783
d3d5cb2d6866
pick isabelle_version based on build_log database;
wenzelm
parents:
65771
diff
changeset
|
121 |
|
d3d5cb2d6866
pick isabelle_version based on build_log database;
wenzelm
parents:
65771
diff
changeset
|
122 |
def pick(options: Options, rev: String = ""): Option[String] = |
65747 | 123 |
{ |
65783
d3d5cb2d6866
pick isabelle_version based on build_log database;
wenzelm
parents:
65771
diff
changeset
|
124 |
val store = Build_Log.store(options) |
d3d5cb2d6866
pick isabelle_version based on build_log database;
wenzelm
parents:
65771
diff
changeset
|
125 |
using(store.open_database())(db => |
d3d5cb2d6866
pick isabelle_version based on build_log database;
wenzelm
parents:
65771
diff
changeset
|
126 |
{ |
65807 | 127 |
val days = options.int("build_log_history") max history |
128 |
val items = recent_items(db, days = days, rev = rev, sql = sql) |
|
65808 | 129 |
def runs = unknown_runs(items) |
65783
d3d5cb2d6866
pick isabelle_version based on build_log database;
wenzelm
parents:
65771
diff
changeset
|
130 |
|
65789 | 131 |
val known_rev = |
65807 | 132 |
rev != "" && items.exists(item => item.known && item.isabelle_version == rev) |
65789 | 133 |
|
65809 | 134 |
if (historic || known_rev) { |
65789 | 135 |
val longest_run = |
65808 | 136 |
(List.empty[Item] /: runs)({ case (item1, item2) => |
65789 | 137 |
if (item1.length >= item2.length) item1 else item2 |
138 |
}) |
|
139 |
if (longest_run.isEmpty) None |
|
140 |
else Some(longest_run(longest_run.length / 2).isabelle_version) |
|
65783
d3d5cb2d6866
pick isabelle_version based on build_log database;
wenzelm
parents:
65771
diff
changeset
|
141 |
} |
65808 | 142 |
else if (rev != "") Some(rev) |
143 |
else runs.flatten.headOption.map(_.isabelle_version) |
|
65783
d3d5cb2d6866
pick isabelle_version based on build_log database;
wenzelm
parents:
65771
diff
changeset
|
144 |
}) |
65747 | 145 |
} |
65732 | 146 |
} |
64231
dbc8294c75d3
added remote_build_history tasks: parallel on several remote hosts;
wenzelm
parents:
64220
diff
changeset
|
147 |
|
65806 | 148 |
val remote_builds_old: List[Remote_Build] = |
149 |
List( |
|
150 |
Remote_Build("Poly/ML test", "lxbroy8", |
|
151 |
options = "-m32 -B -M1x2,2 -t polyml-test -e 'init_component /home/isabelle/contrib/polyml-5.7-20170217'", |
|
152 |
args = "-N -g timing", |
|
153 |
detect = Build_Log.Prop.build_tags + " = " + SQL.string("polyml-test")), |
|
154 |
Remote_Build("Mac OS X 10.8 Mountain Lion", "macbroy30", options = "-m32 -M2", args = "-a", |
|
155 |
detect = Build_Log.Prop.build_start + " < date '2017-03-03'")) |
|
156 |
||
157 |
||
158 |
val remote_builds: List[List[Remote_Build]] = |
|
65732 | 159 |
{ |
64231
dbc8294c75d3
added remote_build_history tasks: parallel on several remote hosts;
wenzelm
parents:
64220
diff
changeset
|
160 |
List( |
65809 | 161 |
List(Remote_Build("Poly/ML 5.7 Linux", "lxbroy8", history = 90, historic = true, |
65805
d3c5898f1a5e
updated to polyml-5.7 for testing (not yet ready for production use);
wenzelm
parents:
65802
diff
changeset
|
162 |
options = "-m32 -B -M1x2,2 -t polyml-5.7 -e 'init_component /home/isabelle/contrib/polyml-5.7'", |
65732 | 163 |
args = "-N -g timing", |
65805
d3c5898f1a5e
updated to polyml-5.7 for testing (not yet ready for production use);
wenzelm
parents:
65802
diff
changeset
|
164 |
detect = Build_Log.Prop.build_tags + " = " + SQL.string("polyml-5.7"))), |
65764 | 165 |
List(Remote_Build("Linux A", "lxbroy9", |
65732 | 166 |
options = "-m32 -B -M1x2,2", args = "-N -g timing")), |
65809 | 167 |
List(Remote_Build("Linux B", "lxbroy10", history = 90, historic = true, |
65732 | 168 |
options = "-m32 -B -M1x4,2,4,6", args = "-N -g timing")), |
64351 | 169 |
List( |
65768 | 170 |
Remote_Build("Mac OS X 10.9 Mavericks", "macbroy2", options = "-m32 -M8", args = "-a", |
65732 | 171 |
detect = Build_Log.Prop.build_tags + " IS NULL"), |
65768 | 172 |
Remote_Build("Mac OS X 10.9 Mavericks, quick_and_dirty", "macbroy2", |
65732 | 173 |
options = "-m32 -M8 -t quick_and_dirty", args = "-a -o quick_and_dirty", |
174 |
detect = Build_Log.Prop.build_tags + " = " + SQL.string("quick_and_dirty")), |
|
65768 | 175 |
Remote_Build("Mac OS X 10.9 Mavericks, skip_proofs", "macbroy2", |
65732 | 176 |
options = "-m32 -M8 -t skip_proofs", args = "-a -o skip_proofs", |
177 |
detect = Build_Log.Prop.build_tags + " = " + SQL.string("skip_proofs"))), |
|
65768 | 178 |
List( |
179 |
Remote_Build("Mac OS X 10.12 Sierra", "macbroy30", options = "-m32 -M2", args = "-a", |
|
180 |
detect = Build_Log.Prop.build_start + " > date '2017-03-03'")), |
|
181 |
List(Remote_Build("Mac OS X 10.10 Yosemite", "macbroy31", options = "-m32 -M2", args = "-a")), |
|
64351 | 182 |
List( |
65802 | 183 |
Remote_Build("Windows", "vmnipkow9", history = 90, shared_home = false, |
65732 | 184 |
options = "-m32 -M4", args = "-a", |
185 |
detect = Build_Log.Settings.ML_PLATFORM + " = " + SQL.string("x86-windows")), |
|
65802 | 186 |
Remote_Build("Windows", "vmnipkow9", history = 90, shared_home = false, |
65732 | 187 |
options = "-m64 -M4", args = "-a", |
188 |
detect = Build_Log.Settings.ML_PLATFORM + " = " + SQL.string("x86_64-windows")))) |
|
189 |
} |
|
64231
dbc8294c75d3
added remote_build_history tasks: parallel on several remote hosts;
wenzelm
parents:
64220
diff
changeset
|
190 |
|
dbc8294c75d3
added remote_build_history tasks: parallel on several remote hosts;
wenzelm
parents:
64220
diff
changeset
|
191 |
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
|
192 |
{ |
303976a45afe
shared_home is default for classic isatest home setup;
wenzelm
parents:
64277
diff
changeset
|
193 |
val task_name = "build_history-" + r.host |
303976a45afe
shared_home is default for classic isatest home setup;
wenzelm
parents:
64277
diff
changeset
|
194 |
Logger_Task(task_name, logger => |
64231
dbc8294c75d3
added remote_build_history tasks: parallel on several remote hosts;
wenzelm
parents:
64220
diff
changeset
|
195 |
{ |
dbc8294c75d3
added remote_build_history tasks: parallel on several remote hosts;
wenzelm
parents:
64220
diff
changeset
|
196 |
using(logger.ssh_context.open_session(host = r.host, user = r.user, port = r.port))( |
64259 | 197 |
ssh => |
64231
dbc8294c75d3
added remote_build_history tasks: parallel on several remote hosts;
wenzelm
parents:
64220
diff
changeset
|
198 |
{ |
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
|
199 |
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
|
200 |
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
|
201 |
|
64468
ed8940d6295c
back to more elementary result (see 5f49765a25ec): avoid concurrent use of ssh channel;
wenzelm
parents:
64452
diff
changeset
|
202 |
val (results, _) = |
ed8940d6295c
back to more elementary result (see 5f49765a25ec): avoid concurrent use of ssh channel;
wenzelm
parents:
64452
diff
changeset
|
203 |
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
|
204 |
isabelle_repos, |
ed8940d6295c
back to more elementary result (see 5f49765a25ec): avoid concurrent use of ssh channel;
wenzelm
parents:
64452
diff
changeset
|
205 |
isabelle_repos.ext(r.host), |
64538 | 206 |
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
|
207 |
self_update = self_update, |
ed8940d6295c
back to more elementary result (see 5f49765a25ec): avoid concurrent use of ssh channel;
wenzelm
parents:
64452
diff
changeset
|
208 |
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
|
209 |
options = |
64479 | 210 |
"-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
|
211 |
args = "-o timeout=10800 " + r.args) |
64346 | 212 |
|
64481 | 213 |
for ((log_name, bytes) <- results) { |
214 |
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
|
215 |
Bytes.write(logger.log_dir + Path.explode(log_name), bytes) |
64481 | 216 |
} |
64231
dbc8294c75d3
added remote_build_history tasks: parallel on several remote hosts;
wenzelm
parents:
64220
diff
changeset
|
217 |
}) |
dbc8294c75d3
added remote_build_history tasks: parallel on several remote hosts;
wenzelm
parents:
64220
diff
changeset
|
218 |
}) |
64294
303976a45afe
shared_home is default for classic isatest home setup;
wenzelm
parents:
64277
diff
changeset
|
219 |
} |
64231
dbc8294c75d3
added remote_build_history tasks: parallel on several remote hosts;
wenzelm
parents:
64220
diff
changeset
|
220 |
|
65747 | 221 |
val build_status_profiles: List[Build_Status.Profile] = |
65768 | 222 |
(remote_builds_old :: remote_builds).flatten.map(_.profile) |
65747 | 223 |
|
65746 | 224 |
|
64192 | 225 |
|
226 |
/** task logging **/ |
|
64171 | 227 |
|
64193 | 228 |
sealed case class Logger_Task(name: String = "", body: Logger => Unit) |
64154 | 229 |
|
64257 | 230 |
class Log_Service private[Isabelle_Cronjob](progress: Progress, val ssh_context: SSH.Context) |
64171 | 231 |
{ |
64219 | 232 |
current_log.file.delete |
233 |
||
64171 | 234 |
private val thread: Consumer_Thread[String] = |
235 |
Consumer_Thread.fork("cronjob: logger", daemon = true)( |
|
236 |
consume = (text: String) => |
|
64219 | 237 |
{ // critical |
238 |
File.append(current_log, text + "\n") |
|
239 |
File.append(cumulative_log, text + "\n") |
|
64171 | 240 |
progress.echo(text) |
241 |
true |
|
242 |
}) |
|
243 |
||
244 |
def shutdown() { thread.shutdown() } |
|
245 |
||
246 |
val hostname = Isabelle_System.hostname() |
|
247 |
||
248 |
def log(date: Date, task_name: String, msg: String): Unit = |
|
64193 | 249 |
if (task_name != "") |
250 |
thread.send( |
|
251 |
"[" + Build_Log.print_date(date) + ", " + hostname + ", " + task_name + "]: " + msg) |
|
64171 | 252 |
|
253 |
def start_logger(start_date: Date, task_name: String): Logger = |
|
254 |
new Logger(this, start_date, task_name) |
|
64154 | 255 |
|
64171 | 256 |
def run_task(start_date: Date, task: Logger_Task) |
257 |
{ |
|
258 |
val logger = start_logger(start_date, task.name) |
|
259 |
val res = Exn.capture { task.body(logger) } |
|
260 |
val end_date = Date.now() |
|
261 |
val err = |
|
262 |
res match { |
|
263 |
case Exn.Res(_) => None |
|
64295 | 264 |
case Exn.Exn(exn) => |
64410 | 265 |
System.err.println("Exception trace for " + quote(task.name) + ":") |
64397 | 266 |
exn.printStackTrace() |
64295 | 267 |
val first_line = Library.split_lines(Exn.message(exn)).headOption getOrElse "exception" |
268 |
Some(first_line) |
|
64171 | 269 |
} |
270 |
logger.log_end(end_date, err) |
|
271 |
} |
|
272 |
||
273 |
def fork_task(start_date: Date, task: Logger_Task): Task = |
|
274 |
new Task(task.name, run_task(start_date, task)) |
|
275 |
} |
|
276 |
||
277 |
class Logger private[Isabelle_Cronjob]( |
|
278 |
val log_service: Log_Service, val start_date: Date, val task_name: String) |
|
64162 | 279 |
{ |
64257 | 280 |
def ssh_context: SSH.Context = log_service.ssh_context |
65640 | 281 |
def options: Options = ssh_context.options |
64231
dbc8294c75d3
added remote_build_history tasks: parallel on several remote hosts;
wenzelm
parents:
64220
diff
changeset
|
282 |
|
64171 | 283 |
def log(date: Date, msg: String): Unit = log_service.log(date, task_name, msg) |
284 |
||
285 |
def log_end(end_date: Date, err: Option[String]) |
|
286 |
{ |
|
287 |
val elapsed_time = end_date.time - start_date.time |
|
288 |
val msg = |
|
289 |
(if (err.isEmpty) "finished" else "ERROR " + err.get) + |
|
64197 | 290 |
(if (elapsed_time.seconds < 3.0) "" else " (" + elapsed_time.message_hms + " elapsed time)") |
64171 | 291 |
log(end_date, msg) |
292 |
} |
|
293 |
||
64195 | 294 |
val log_dir: Path = main_dir + Build_Log.log_subdir(start_date) |
295 |
||
296 |
Isabelle_System.mkdirs(log_dir) |
|
64171 | 297 |
log(start_date, "started") |
298 |
} |
|
299 |
||
300 |
class Task private[Isabelle_Cronjob](name: String, body: => Unit) |
|
301 |
{ |
|
302 |
private val future: Future[Unit] = Future.thread("cronjob: " + name) { body } |
|
303 |
def is_finished: Boolean = future.is_finished |
|
64162 | 304 |
} |
64153
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
305 |
|
64170 | 306 |
|
307 |
||
64153
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
308 |
/** cronjob **/ |
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
309 |
|
64187 | 310 |
def cronjob(progress: Progress, exclude_task: Set[String]) |
64153
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
311 |
{ |
64171 | 312 |
/* soft lock */ |
64153
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
313 |
|
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
314 |
val still_running = |
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
315 |
try { Some(File.read(main_state_file)) } |
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
316 |
catch { case ERROR(_) => None } |
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
317 |
|
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
318 |
still_running match { |
64170 | 319 |
case None | Some("") => |
64153
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
320 |
case Some(running) => |
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
321 |
error("Isabelle cronjob appears to be still running: " + running) |
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
322 |
} |
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
323 |
|
64199 | 324 |
|
325 |
/* log service */ |
|
326 |
||
64257 | 327 |
val log_service = new Log_Service(progress, SSH.init_context(Options.init())) |
64154 | 328 |
|
64199 | 329 |
def run(start_date: Date, task: Logger_Task) { log_service.run_task(start_date, task) } |
330 |
||
331 |
def run_now(task: Logger_Task) { run(Date.now(), task) } |
|
64154 | 332 |
|
333 |
||
64199 | 334 |
/* structured tasks */ |
64184 | 335 |
|
64350
3af8566788e7
remote_builds has PAR-SEQ semantics of old isatest-makedist;
wenzelm
parents:
64348
diff
changeset
|
336 |
def SEQ(tasks: List[Logger_Task]): Logger_Task = Logger_Task(body = _ => |
64193 | 337 |
for (task <- tasks.iterator if !exclude_task(task.name) || task.name == "") |
64199 | 338 |
run_now(task)) |
64153
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
339 |
|
64350
3af8566788e7
remote_builds has PAR-SEQ semantics of old isatest-makedist;
wenzelm
parents:
64348
diff
changeset
|
340 |
def PAR(tasks: List[Logger_Task]): Logger_Task = Logger_Task(body = _ => |
64170 | 341 |
{ |
64199 | 342 |
@tailrec def join(running: List[Task]) |
343 |
{ |
|
344 |
running.partition(_.is_finished) match { |
|
345 |
case (Nil, Nil) => |
|
346 |
case (Nil, _ :: _) => Thread.sleep(500); join(running) |
|
347 |
case (_ :: _, remaining) => join(remaining) |
|
348 |
} |
|
64170 | 349 |
} |
64199 | 350 |
val start_date = Date.now() |
351 |
val running = |
|
64350
3af8566788e7
remote_builds has PAR-SEQ semantics of old isatest-makedist;
wenzelm
parents:
64348
diff
changeset
|
352 |
for (task <- tasks if !exclude_task(task.name)) |
64199 | 353 |
yield log_service.fork_task(start_date, task) |
354 |
join(running) |
|
355 |
}) |
|
64193 | 356 |
|
64170 | 357 |
|
358 |
/* main */ |
|
359 |
||
64199 | 360 |
val main_start_date = Date.now() |
361 |
File.write(main_state_file, main_start_date + " " + log_service.hostname) |
|
362 |
||
64232
367d83d6030e
clarified hg.id operation, with explicit tip as default;
wenzelm
parents:
64231
diff
changeset
|
363 |
val rev = Mercurial.repository(isabelle_repos).id() |
64231
dbc8294c75d3
added remote_build_history tasks: parallel on several remote hosts;
wenzelm
parents:
64220
diff
changeset
|
364 |
|
64193 | 365 |
run(main_start_date, |
65783
d3d5cb2d6866
pick isabelle_version based on build_log database;
wenzelm
parents:
65771
diff
changeset
|
366 |
Logger_Task("isabelle_cronjob", logger => |
64231
dbc8294c75d3
added remote_build_history tasks: parallel on several remote hosts;
wenzelm
parents:
64220
diff
changeset
|
367 |
run_now( |
64405
81bac77929d9
just one task to identify Isabelle + AFP repository snapshots and build release;
wenzelm
parents:
64399
diff
changeset
|
368 |
SEQ(List(build_release, build_history_base, |
65783
d3d5cb2d6866
pick isabelle_version based on build_log database;
wenzelm
parents:
65771
diff
changeset
|
369 |
PAR(remote_builds.map(seq => |
d3d5cb2d6866
pick isabelle_version based on build_log database;
wenzelm
parents:
65771
diff
changeset
|
370 |
SEQ(seq.flatMap(r => r.pick(logger.options, rev).map(remote_build_history(_, r)))))), |
65666
45d0692bb019
incremental download of Jenkins log files, which are also added to database;
wenzelm
parents:
65647
diff
changeset
|
371 |
Logger_Task("jenkins_logs", _ => Jenkins.download_logs(jenkins_jobs, main_dir)), |
65770 | 372 |
Logger_Task("build_log_database", |
373 |
logger => Isabelle_Devel.build_log_database(logger.options)), |
|
374 |
Logger_Task("build_status", |
|
65793 | 375 |
logger => Isabelle_Devel.build_status(logger.options))))))) |
64153
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
376 |
|
64171 | 377 |
log_service.shutdown() |
64170 | 378 |
|
64153
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
379 |
main_state_file.file.delete |
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
380 |
} |
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
381 |
|
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
382 |
|
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
383 |
|
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
384 |
/** command line entry point **/ |
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
385 |
|
64148 | 386 |
def main(args: Array[String]) |
387 |
{ |
|
388 |
Command_Line.tool0 { |
|
389 |
var force = false |
|
390 |
var verbose = false |
|
64187 | 391 |
var exclude_task = Set.empty[String] |
64148 | 392 |
|
393 |
val getopts = Getopts(""" |
|
394 |
Usage: Admin/cronjob/main [OPTIONS] |
|
395 |
||
396 |
Options are: |
|
397 |
-f apply force to do anything |
|
398 |
-v verbose |
|
64187 | 399 |
-x NAME exclude tasks with this name |
64148 | 400 |
""", |
401 |
"f" -> (_ => force = true), |
|
64187 | 402 |
"v" -> (_ => verbose = true), |
403 |
"x:" -> (arg => exclude_task += arg)) |
|
64148 | 404 |
|
405 |
val more_args = getopts(args) |
|
406 |
if (more_args.nonEmpty) getopts.usage() |
|
407 |
||
64909 | 408 |
val progress = if (verbose) new Console_Progress() else No_Progress |
64148 | 409 |
|
64187 | 410 |
if (force) cronjob(progress, exclude_task) |
64153
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
411 |
else error("Need to apply force to do anything") |
64148 | 412 |
} |
413 |
} |
|
414 |
} |