forked from golang/build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.go
70 lines (61 loc) · 1.61 KB
/
log.go
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
// Copyright 2016 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"context"
"fmt"
"log"
"time"
"cloud.google.com/go/datastore"
"golang.org/x/build/types"
)
// Process is a datastore record about the lifetime of a coordinator process.
//
// Example GQL query:
// SELECT * From Process where LastHeartbeat > datetime("2016-01-01T00:00:00Z")
type ProcessRecord struct {
ID string
Start time.Time
LastHeartbeat time.Time
// TODO: version, who deployed, CoreOS version, Docker version,
// GCE instance type?
}
func updateInstanceRecord() {
if dsClient == nil {
return
}
ctx := context.Background()
for {
key := datastore.NameKey("Process", processID, nil)
_, err := dsClient.Put(ctx, key, &ProcessRecord{
ID: processID,
Start: processStartTime,
LastHeartbeat: time.Now(),
})
if err != nil {
log.Printf("datastore Process Put: %v", err)
}
time.Sleep(30 * time.Second)
}
}
func putBuildRecord(br *types.BuildRecord) {
if dsClient == nil {
return
}
ctx := context.Background()
key := datastore.NameKey("Build", br.ID, nil)
if _, err := dsClient.Put(ctx, key, br); err != nil {
log.Printf("datastore Build Put: %v", err)
}
}
func putSpanRecord(sr *types.SpanRecord) {
if dsClient == nil {
return
}
ctx := context.Background()
key := datastore.NameKey("Span", fmt.Sprintf("%s-%v-%v", sr.BuildID, sr.StartTime.UnixNano(), sr.Event), nil)
if _, err := dsClient.Put(ctx, key, sr); err != nil {
log.Printf("datastore Span Put: %v", err)
}
}