chore: move job emitter to service

This commit is contained in:
Jason Song 2022-11-18 11:43:42 +08:00
parent f57e6999a2
commit dd417a3270
6 changed files with 19 additions and 10 deletions

View File

@ -11,18 +11,11 @@ import (
"code.gitea.io/gitea/models/webhook"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/graceful"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/queue"
"github.com/nektos/act/pkg/model"
)
func Init() {
jobEmitterQueue = queue.CreateUniqueQueue("bots_ready_job", jobEmitterQueueHandle, new(jobUpdate))
go graceful.GetManager().RunWithShutdownFns(jobEmitterQueue.Run)
}
func ListWorkflows(commit *git.Commit) (git.Entries, error) {
tree, err := commit.SubTree(".gitea/workflows")
if _, ok := err.(git.ErrNotExist); ok {

View File

@ -19,6 +19,7 @@ import (
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
bot_service "code.gitea.io/gitea/services/bots"
secret_service "code.gitea.io/gitea/services/secrets"
runnerv1 "gitea.com/gitea/proto-go/runner/v1"
@ -214,7 +215,7 @@ func (s *Service) UpdateTask(
}
if req.Msg.State.Result != runnerv1.Result_RESULT_UNSPECIFIED {
if err := bots.EmitJobsIfReady(task.Job.RunID); err != nil {
if err := bot_service.EmitJobsIfReady(task.Job.RunID); err != nil {
log.Error("Emit ready jobs of run %d: %v", task.Job.RunID, err)
}
}

View File

@ -11,7 +11,6 @@ import (
"code.gitea.io/gitea/models"
asymkey_model "code.gitea.io/gitea/models/asymkey"
"code.gitea.io/gitea/modules/bots"
"code.gitea.io/gitea/modules/cache"
"code.gitea.io/gitea/modules/eventsource"
"code.gitea.io/gitea/modules/git"
@ -41,6 +40,7 @@ import (
"code.gitea.io/gitea/services/auth"
"code.gitea.io/gitea/services/auth/source/oauth2"
"code.gitea.io/gitea/services/automerge"
bot_service "code.gitea.io/gitea/services/bots"
"code.gitea.io/gitea/services/cron"
"code.gitea.io/gitea/services/mailer"
markup_service "code.gitea.io/gitea/services/markup"
@ -175,7 +175,7 @@ func GlobalInitInstalled(ctx context.Context) {
auth.Init()
svg.Init()
bots.Init()
bot_service.Init()
// Finally start up the cron
cron.NewContext(ctx)

15
services/bots/bots.go Normal file
View File

@ -0,0 +1,15 @@
// Copyright 2022 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package bots
import (
"code.gitea.io/gitea/modules/graceful"
"code.gitea.io/gitea/modules/queue"
)
func Init() {
jobEmitterQueue = queue.CreateUniqueQueue("bots_ready_job", jobEmitterQueueHandle, new(jobUpdate))
go graceful.GetManager().RunWithShutdownFns(jobEmitterQueue.Run)
}