chore(piepline): add runtime package.

Signed-off-by: Bo-Yi Wu <[email protected]>
This commit is contained in:
Bo-Yi Wu authored and Jason Song committed 2022-11-24 15:37:01 +08:00
1 parent bca586ffd0
commit 7d55fd57c9
7 files changed
+99 -211

No files matched your search

+5
View File
@@ -2,10 +2,15 @@ package client
import (
"context"
v1 "gitea.com/gitea/proto/gen/proto/v1"
)
// A Client manages communication with the runner.
type Client interface {
// Ping sends a ping message to the server to test connectivity.
Ping(ctx context.Context, machine string) error
// Request requests the next available build stage for execution.
Request(ctx context.Context) (*v1.Stage, error)
}
+19
View File
@@ -83,3 +83,22 @@ func (p *HTTPClient) Ping(ctx context.Context, machine string) error {
_, err := client.Ping(ctx, req)
return err
}
// Ping sends a ping message to the server to test connectivity.
func (p *HTTPClient) Request(ctx context.Context) (*v1.Stage, error) {
client := v1connect.NewRunnerServiceClient(
p.Client,
p.Endpoint,
p.opts...,
)
req := connect.NewRequest(&v1.ConnectRequest{})
req.Header().Set("X-Gitea-Token", p.Secret)
res, err := client.Connect(ctx, req)
if err != nil {
return nil, err
}
return res.Msg.Stage, err
}