-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.go
71 lines (54 loc) · 1.48 KB
/
user.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
71
package main
import (
// "github.com/davecgh/go-spew/spew"
"time"
"github.com/jmcvetta/neoism"
"github.com/juju/errors"
)
func (p *Engine) completeUsers(db *neoism.Database) error {
res, err := p.execQuery(db, CYPHER_USERS_NEED_COMPLETION, nil)
if err != nil {
return errors.Annotate(err, "exec users need completion")
}
ids := res.FilterResultsBy("id").ToInt64Slice()
if len(ids) == 0 {
return nil
}
logger.Infof("%d user ids need completion -> fetch", len(ids))
twUsers, err := p.api.GetUsersLookupByIds(ids, nil)
if err != nil {
if apiErr, ok := err.(*anaconda.ApiError); ok {
if apiErr.StatusCode == 404 {
logger.Infof("mark user #%s as protected", idStr)
_, err = p.execQuery(db, CYPHER_USER_SET_PROTECTED, neoism.Props{
"id": idStr,
})
if err != nil {
return errors.Annotate(err, "set user protected")
}
}
}
return errors.Annotate(err, "lookup users by ids")
}
props := neoism.Props{
"users": twUsers,
}
logger.Infof("got data for %d users -> apply", len(twUsers))
if _, err := p.execQuery(db, CYPHER_USERS_UPDATE_BY_ID, props); err != nil {
return errors.Annotate(err, "users update by id")
}
return nil
}
func (p *Engine) CompleteUsers() error {
logger.Info("complete users")
db, err := p.ensureClients()
if err != nil {
return errors.Annotate(err, "ensure clients")
}
for {
if err := p.completeUsers(db); err != nil {
return errors.Annotate(err, "complete users")
}
time.Sleep(10 * time.Second)
}
}