From b7aaa3ba774173b2a791e840cdc6a507fe5cc37f Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Thu, 13 Oct 2022 17:22:39 +0800 Subject: [PATCH] chore(runner): support update runner status. --- routers/api/bots/runner/runner.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/routers/api/bots/runner/runner.go b/routers/api/bots/runner/runner.go index b6533d9918..de43156e53 100644 --- a/routers/api/bots/runner/runner.go +++ b/routers/api/bots/runner/runner.go @@ -36,6 +36,27 @@ type Service struct { runnerv1connect.UnimplementedRunnerServiceHandler } +// UpdateRunner update runner status or other data. +func (s *Service) UpdateRunner( + ctx context.Context, + req *connect.Request[runnerv1.UpdateRunnerRequest], +) (*connect.Response[runnerv1.UpdateRunnerResponse], error) { + runner := GetRunner(ctx) + + // check status + if runner.Status == req.Msg.Status { + return connect.NewResponse(&runnerv1.UpdateRunnerResponse{}), nil + } + + // update status + runner.Status = req.Msg.Status + if err := bots_model.UpdateRunner(ctx, runner, "status"); err != nil { + return nil, connect.NewError(connect.CodeInternal, err) + } + + return connect.NewResponse(&runnerv1.UpdateRunnerResponse{}), nil +} + // Register for new runner. func (s *Service) Register( ctx context.Context,