From a20b8aa9094a4f1df33a7e4b4af60e8edfbd5b0a Mon Sep 17 00:00:00 2001 From: "Bo-Yi.Wu" Date: Fri, 4 Nov 2022 21:16:08 +0800 Subject: [PATCH] chore(runner): return cancel evnet after upload the log Signed-off-by: Bo-Yi.Wu --- go.mod | 2 +- go.sum | 2 ++ routers/api/bots/runner/runner.go | 18 +++++++++++++++--- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index c548bae8f5..47e2b49ebb 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( code.gitea.io/sdk/gitea v0.15.1 codeberg.org/gusted/mcaptcha v0.0.0-20220723083913-4f3072e1d570 gitea.com/gitea/act_runner v0.0.0-20221015084035-e63e22e8c81d - gitea.com/gitea/proto-go v0.0.0-20221014123629-9116865c883b + gitea.com/gitea/proto-go v0.0.0-20221028125601-35c4f6b05835 gitea.com/go-chi/binding v0.0.0-20220309004920-114340dabecb gitea.com/go-chi/cache v0.2.0 gitea.com/go-chi/captcha v0.0.0-20211013065431-70641c1a35d5 diff --git a/go.sum b/go.sum index 704b4dc4e5..ff785cae89 100644 --- a/go.sum +++ b/go.sum @@ -87,6 +87,8 @@ gitea.com/gitea/act_runner v0.0.0-20221015084035-e63e22e8c81d h1:WdZqNKX1TB0vH1n gitea.com/gitea/act_runner v0.0.0-20221015084035-e63e22e8c81d/go.mod h1:ZDTf3CZrtttQj0EzduNKPRUBPIrPOK6cdx/LFFVX+EE= gitea.com/gitea/proto-go v0.0.0-20221014123629-9116865c883b h1:TSz7VRHfnM/5JwGPgIAjSlDIvcr4pTGfuRMtgMxttmg= gitea.com/gitea/proto-go v0.0.0-20221014123629-9116865c883b/go.mod h1:hD8YwSHusjwjEEgubW6XFvnZuNhMZTHz6lwjfltEt/Y= +gitea.com/gitea/proto-go v0.0.0-20221028125601-35c4f6b05835 h1:27PhT7Nli/pgRo1bDYVZ+hlCKuF9cfFuo+y9muaPVJY= +gitea.com/gitea/proto-go v0.0.0-20221028125601-35c4f6b05835/go.mod h1:hD8YwSHusjwjEEgubW6XFvnZuNhMZTHz6lwjfltEt/Y= gitea.com/go-chi/binding v0.0.0-20220309004920-114340dabecb h1:Yy0Bxzc8R2wxiwXoG/rECGplJUSpXqCsog9PuJFgiHs= gitea.com/go-chi/binding v0.0.0-20220309004920-114340dabecb/go.mod h1:77TZu701zMXWJFvB8gvTbQ92zQ3DQq/H7l5wAEjQRKc= gitea.com/go-chi/cache v0.0.0-20210110083709-82c4c9ce2d5e/go.mod h1:k2V/gPDEtXGjjMGuBJiapffAXTv76H4snSmlJRLUhH0= diff --git a/routers/api/bots/runner/runner.go b/routers/api/bots/runner/runner.go index ca32d582ac..d8e28557c7 100644 --- a/routers/api/bots/runner/runner.go +++ b/routers/api/bots/runner/runner.go @@ -165,9 +165,21 @@ func (s *Service) UpdateTask( ctx context.Context, req *connect.Request[runnerv1.UpdateTaskRequest], ) (*connect.Response[runnerv1.UpdateTaskResponse], error) { - res := connect.NewResponse(&runnerv1.UpdateTaskResponse{}) + // Get Task first + task, err := bots_model.GetTaskByID(ctx, req.Msg.State.Id) + if err != nil { + return nil, status.Errorf(codes.Internal, "can't find the task: %v", err) + } + if task.Result == runnerv1.Result_RESULT_CANCELLED { + return connect.NewResponse(&runnerv1.UpdateTaskResponse{ + State: &runnerv1.TaskState{ + Id: req.Msg.State.Id, + Result: task.Result, + }, + }), nil + } - task, err := bots_model.UpdateTaskByState(req.Msg.State) + task, err = bots_model.UpdateTaskByState(req.Msg.State) if err != nil { return nil, status.Errorf(codes.Internal, "update task: %v", err) } @@ -213,7 +225,7 @@ func (s *Service) UpdateTask( } } - return res, nil + return connect.NewResponse(&runnerv1.UpdateTaskResponse{}), nil } // UpdateLog uploads log of the task.