/
status-update.factor
114 lines (95 loc) · 3.05 KB
/
status-update.factor
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
! Copyright (C) 2010 Slava Pestov.
! See https://factorcode.org/license.txt for BSD license.
USING: accessors assocs calendar combinators db.tuples
furnace.actions furnace.redirection html.forms
http.server.responses io kernel multiline namespaces parser
prettyprint sequences splitting validators webapps.mason.backend
webapps.mason.utils ;
IN: webapps.mason.status-update
: find-builder ( host-name os cpu -- builder )
builder new
swap >>cpu
swap >>os
swap >>host-name
[ select-tuple ] [ dup insert-tuple ] ?unless ;
: update-runs ( builder -- run-id )
[ run new ] dip
{ [ host-name>> >>host-name ]
[ os>> >>os ]
[ cpu>> >>cpu ]
[ current-timestamp>> >>timestamp ]
[ current-git-id>> >>git-id ] } cleave
dup insert-tuple run-id>> ;
: update-benchmarks ( run-id benchmarks -- )
[ benchmark new swap >>run-id ] dip
[ first2 [ >>name ] dip >>duration insert-tuple ] with each ;
: heartbeat ( builder -- )
now >>heartbeat-timestamp
drop ;
: status ( builder status -- )
>>status
now >>current-timestamp
drop ;
: idle ( builder -- ) +idle+ status ;
: git-id ( builder id -- ) >>current-git-id now >>start-timestamp +starting+ status ;
: make-vm ( builder -- ) +make-vm+ status ;
: boot ( builder -- ) +boot+ status ;
: test ( builder -- ) +test+ status ;
: benchmarks ( builder content -- )
[ update-runs ] dip
split-lines parse-fresh first update-benchmarks ;
: report ( builder content status -- )
[
>>last-report
now >>current-timestamp
] dip
+clean+ = [
dup current-git-id>> >>clean-git-id
dup current-timestamp>> >>clean-timestamp
] when
dup current-git-id>> >>last-git-id
dup current-timestamp>> >>last-timestamp
drop ;
: upload ( builder -- ) +upload+ status ;
: finish ( builder -- ) +finish+ status ;
: release ( builder name -- )
>>last-release
dup clean-git-id>> >>release-git-id
drop ;
: update-builder ( builder -- )
"message" value {
{ "heartbeat" [ heartbeat ] }
{ "idle" [ idle ] }
{ "git-id" [ "arg" value git-id ] }
{ "make-vm" [ make-vm ] }
{ "boot" [ boot ] }
{ "test" [ test ] }
{ "report" [ "report" value "arg" value report ] }
{ "benchmarks" [ "report" value benchmarks ] }
{ "upload" [ upload ] }
{ "finish" [ finish ] }
{ "release" [ "arg" value release ] }
} case ;
: <status-update-action> ( -- action )
<action>
[
{
{ "host-name" [ v-one-line ] }
{ "target-cpu" [ v-one-line ] }
{ "target-os" [ v-one-line ] }
{ "message" [ v-one-line ] }
{ "arg" [ [ v-one-line ] v-optional ] }
{ "report" [ ] }
} validate-params
validate-secret
] >>validate
[
[
"host-name" value
"target-os" value
"target-cpu" value
find-builder
[ update-builder ] [ update-tuple ] bi
] with-mason-db
"OK" <text-content>
] >>submit ;