forked from flynn/flynn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
local_client.go
48 lines (41 loc) · 1.07 KB
/
local_client.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
package main
import (
"github.com/flynn/flynn/host/sampi"
"github.com/flynn/flynn/host/types"
"github.com/flynn/flynn/pkg/cluster"
"github.com/flynn/flynn/pkg/rpcplus"
)
func NewLocalClient(host string, c *sampi.Cluster) cluster.LocalClient {
return &localClient{c: c, host: host}
}
type localClient struct {
c *sampi.Cluster
host string
}
func (c *localClient) ListHosts() (map[string]host.Host, error) {
res := make(map[string]host.Host)
return res, c.c.ListHosts(struct{}{}, &res)
}
func (c *localClient) AddJobs(req *host.AddJobsReq) (*host.AddJobsRes, error) {
res := &host.AddJobsRes{}
return res, c.c.AddJobs(req, res)
}
func (c *localClient) RegisterHost(h *host.Host, jobs chan *host.Job) *error {
ch := make(chan interface{})
stream := rpcplus.Stream{Send: ch}
var err error
go func() {
err = c.c.RegisterHost(&c.host, h, stream)
close(ch)
}()
go func() {
for job := range ch {
jobs <- job.(*host.Job).Dup()
}
close(jobs)
}()
return &err
}
func (c *localClient) RemoveJobs(jobs []string) error {
return c.c.RemoveJobs(&c.host, jobs, nil)
}