■ ■ ■ ■ ■ ■
internal/app/api/agent.go
| skipped 3 lines |
4 | 4 | | "encoding/json" |
5 | 5 | | "fmt" |
6 | 6 | | "log" |
| 7 | + | "strconv" |
7 | 8 | | "time" |
8 | 9 | | |
9 | 10 | | "github.com/globalsign/mgo" |
| skipped 20 lines |
30 | 31 | | //GetSecrets api data |
31 | 32 | | func GetAgents() []byte { |
32 | 33 | | //query := bson.M{} |
| 34 | + | anHourAgo := time.Now().Add(-time.Minute) |
33 | 35 | | |
34 | 36 | | session, err := mgo.Dial("127.0.0.1") |
35 | 37 | | if err != nil { |
| skipped 6 lines |
42 | 44 | | |
43 | 45 | | // Query All |
44 | 46 | | var results []Agent |
45 | | - | err = c.Find(bson.M{}).All(&results) |
| 47 | + | err = c.Find(bson.M{"checkIn": bson.M{"$gt": anHourAgo}}).All(&results) |
46 | 48 | | |
47 | 49 | | if err != nil { |
48 | 50 | | panic(err) |
| skipped 173 lines |
222 | 224 | | |
223 | 225 | | //NewCMD command read status |
224 | 226 | | func AgentCreate(agent string, wd string) { |
| 227 | + | timestamp := strconv.FormatInt(time.Now().UTC().UnixNano(), 10) |
225 | 228 | | fmt.Println("creating agent") |
226 | 229 | | fmt.Println(agent) |
227 | | - | query := bson.M{"agent": agent, "working": wd, "checkIn": time.Now()} |
| 230 | + | query := bson.M{"agent": agent, "working": wd, "checkIn": timestamp} |
228 | 231 | | session, err := mgo.Dial("127.0.0.1") |
229 | 232 | | if err != nil { |
230 | 233 | | panic(err) |
| skipped 9 lines |