This repository was archived by the owner on Nov 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresults.w
58 lines (46 loc) · 1.43 KB
/
results.w
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
bring cloud;
pub struct CheckResult {
/** a unique id of the check */
checkid: str;
/** the construct path of the check */
checkpath: str;
/** timestamp the check was run */
timestamp: str;
/** true if the test was successful */
ok: bool;
/** error message if the test failed */
error: str?;
}
/** Centralized storage for check results */
pub class Results {
pub static of(scope: std.IResource): Results {
let root = std.Node.of(scope).root;
let id = "cloud.CheckResults";
let exists: Results? = unsafeCast(root.node.tryFindChild(id));
let rootAsResource: Results = unsafeCast(root);
return exists ?? new Results() as id in rootAsResource;
}
bucket: cloud.Bucket;
init() {
this.bucket = new cloud.Bucket() as "results";
}
pub inflight store(result: CheckResult) {
let checkid = result.checkid;
let body = Json.stringify(result);
let key = this.makeLatestKey(checkid);
log("storing ${key}");
this.bucket.putJson(key, result);
this.bucket.putJson(this.makeKey(checkid, "${result.timestamp}.json"), result);
}
pub inflight latest(checkid: str): CheckResult? {
let key = this.makeLatestKey(checkid);
let s = this.bucket.tryGetJson(key);
return CheckResult.fromJson(s);
}
inflight makeKey(checkid: str, key: str): str {
return "${checkid}/${key}";
}
inflight makeLatestKey(checkid: str): str {
return this.makeKey(checkid, "latest.json");
}
}