2022-08-13 22:41:01 +08:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-08-14 13:29:00 +08:00
|
|
|
|
2022-08-17 14:25:14 +08:00
|
|
|
runnerv1 "gitea.com/gitea/proto-go/runner/v1"
|
2022-08-13 22:41:01 +08:00
|
|
|
)
|
|
|
|
|
2022-08-28 14:05:56 +08:00
|
|
|
type Filter struct {
|
|
|
|
Kind string `json:"kind"`
|
|
|
|
Type string `json:"type"`
|
|
|
|
OS string `json:"os"`
|
|
|
|
Arch string `json:"arch"`
|
|
|
|
Capacity int `json:"capacity"`
|
|
|
|
}
|
|
|
|
|
2022-08-13 22:41:01 +08:00
|
|
|
// 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
|
2022-08-14 13:29:00 +08:00
|
|
|
|
2022-08-28 14:05:56 +08:00
|
|
|
// Register for new runner.
|
|
|
|
Register(ctx context.Context, args *runnerv1.RegisterRequest) (*runnerv1.Runner, error)
|
2022-09-01 15:09:22 +08:00
|
|
|
|
|
|
|
// Request requests the next available build stage for execution.
|
|
|
|
Request(ctx context.Context, args *runnerv1.RequestRequest) (*runnerv1.Stage, error)
|
2022-09-01 22:00:41 +08:00
|
|
|
|
|
|
|
// Update updates the build stage.
|
|
|
|
Update(ctxt context.Context, args *runnerv1.UpdateRequest) error
|
|
|
|
|
|
|
|
// UpdateStep updates the build step.
|
|
|
|
UpdateStep(ctx context.Context, args *runnerv1.UpdateStepRequest) error
|
2022-08-13 22:41:01 +08:00
|
|
|
}
|
2022-09-03 15:57:53 +08:00
|
|
|
|
|
|
|
type contextKey string
|
|
|
|
|
|
|
|
const clientContextKey = contextKey("gitea.rpc.client")
|
|
|
|
|
|
|
|
// FromContext returns the client from the context.
|
|
|
|
func FromContext(ctx context.Context) Client {
|
|
|
|
val := ctx.Value(clientContextKey)
|
|
|
|
if val != nil {
|
|
|
|
if c, ok := val.(Client); ok {
|
|
|
|
return c
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithClient returns a new context with the given client.
|
|
|
|
func WithClient(ctx context.Context, c Client) context.Context {
|
|
|
|
return context.WithValue(ctx, clientContextKey, c)
|
|
|
|
}
|