Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore: delete application runner (#7971)

Danny Xu5a2ce906c780
diff --git a/backend/runner/apprun/runner.go b/backend/runner/apprun/runner.go
deleted file mode 100644
index 44edc1e15c..0000000000
--- a/backend/runner/apprun/runner.go
+++ /dev/null
@@ -1,641 +0,0 @@
-// Package apprun is an application runner for scanning Feishu approval instances.
-package apprun
-
-import (
- "context"
- "encoding/json"
- "fmt"
- "sync"
- "time"
-
- "github.com/gosimple/slug"
- "github.com/pkg/errors"
- "go.uber.org/zap"
-
- "github.com/bytebase/bytebase/backend/common/log"
- "github.com/bytebase/bytebase/backend/component/activity"
- "github.com/bytebase/bytebase/backend/component/config"
- enterpriseAPI "github.com/bytebase/bytebase/backend/enterprise/api"
- api "github.com/bytebase/bytebase/backend/legacyapi"
- "github.com/bytebase/bytebase/backend/plugin/app/feishu"
- "github.com/bytebase/bytebase/backend/store"
- "github.com/bytebase/bytebase/backend/utils"
-)
-
-// NewRunner returns a runner.
-func NewRunner(
- store *store.Store,
- activityManager *activity.Manager,
- feishuProvider *feishu.Provider,
- profile config.Profile,
- licenseService enterpriseAPI.LicenseService,
-) *Runner {
- return &Runner{
- store: store,
- activityManager: activityManager,
- p: feishuProvider,
- profile: profile,
- licenseService: licenseService,
- }
-}
-
-// Runner is a runner which periodically checks external approval status and approve the corresponding stages.
-type Runner struct {
- store *store.Store
- activityManager *activity.Manager
- p *feishu.Provider
- profile config.Profile
- licenseService enterpriseAPI.LicenseService
-}
-
-// Run runs the ApplicationRunner.
-func (r *Runner) Run(ctx context.Context, wg *sync.WaitGroup) {
- ticker := time.NewTicker(r.profile.AppRunnerInterval)
- defer ticker.Stop()
- defer wg.Done()
- log.Debug(fmt.Sprintf("Application runner started and will run every %v", r.profile.AppRunnerInterval))
- // Try to update approval definition if external approval is enabled, because our approval definition may have changed.
- if err := r.tryUpdateApprovalDefinition(ctx); err != nil {
- log.Error("failed to update approval definition on application runner start", zap.Error(err))
- }
- for {
- select {
- case <-ticker.C:
- func() {
- setting, err := r.store.GetAppIMApprovalSetting(ctx)
- if err != nil {
- if !errors.Is(err, context.Canceled) {
- log.Error("failed to get IM setting", zap.Error(err))
- }
- return
- }
- if setting == nil {
- return
- }
- if !setting.ExternalApproval.Enabled {
- return
- }
-
- issueByID := make(map[int]*store.IssueMessage)
- stagesByPipelineID := make(map[int][]*store.StageMessage)
-
- needAttention := true
- issues, err := r.store.ListIssueV2(ctx, &store.FindIssueMessage{
- StatusList: []api.IssueStatus{api.IssueOpen},
- NeedAttention: &needAttention,
- })
- if err != nil {
- log.Error("failed to find issues", zap.Error(err))
- return
- }
- for _, issue := range issues {
- if issue.PipelineUID == nil {
- continue
- }
- issueByID[issue.UID] = issue
- stages, err := r.store.ListStageV2(ctx, *issue.PipelineUID)
- if err != nil {
- log.Error("failed to list stages", zap.Int("pipeline", *issue.PipelineUID), zap.Error(err))
- return
- }
- stagesByPipelineID[*issue.PipelineUID] = stages
- r.scheduleApproval(ctx, issue, stages, setting)
- }
-
- externalApprovalType := api.ExternalApprovalTypeFeishu
- externalApprovalList, err := r.store.ListExternalApprovalV2(ctx, &store.ListExternalApprovalMessage{
- Type: &externalApprovalType,
- })
- if err != nil {
- log.Error("failed to find external approval list", zap.Error(err))
- return
- }
-
- for _, externalApproval := range externalApprovalList {
- switch externalApproval.Type {
- case api.ExternalApprovalTypeFeishu:
- var payload api.ExternalApprovalPayloadFeishu
- if err := json.Unmarshal([]byte(externalApproval.Payload), &payload); err != nil {
- log.Error("failed to unmarshal to ExternalApprovalPayloadFeishu", zap.String("payload", externalApproval.Payload), zap.Error(err))
- continue
- }
-
- if payload.Rejected {
- continue
- }
-
- issue, ok := issueByID[externalApproval.IssueUID]
- if !ok {
- // issueByID is fetched before externalApprovalList and is not fresh,
- // so it's ok not to find the corresponding issue of an externalApproval as
- // it will be handled next round anyway.
- continue
- }
- stages, ok := stagesByPipelineID[*issue.PipelineUID]
- if !ok {
- log.Debug("expect to have found pipeline in application runner", zap.Int("pipeline_id", *issue.PipelineUID))
- continue
- }
- activeStage := utils.GetActiveStage(stages)
-
- if issue.Status != api.IssueOpen || activeStage == nil {
- if err := r.CancelExternalApproval(ctx, issue.UID, api.ExternalApprovalCancelReasonIssueNotOpen); err != nil {
- log.Error("failed to cancel external approval", zap.Error(err))
- }
- continue
- }
-
- status, err := r.p.GetExternalApprovalStatus(ctx, feishu.TokenCtx{
- AppID: setting.AppID,
- AppSecret: setting.AppSecret,
- }, payload.InstanceCode)
- if err != nil {
- if errors.Is(err, context.Canceled) {
- break
- }
- log.Error("failed to get external approval", zap.String("instanceCode", payload.InstanceCode), zap.Error(err))
- continue
- }
-
- switch status {
- case feishu.ApprovalStatusApproved:
- // double check
- if activeStage.ID == payload.StageID && payload.AssigneeID == issue.Assignee.ID {
- // Approve stage.
- if err := func() error {
- // TODO(d): optimize the active stage tasks.
- approved, err := utils.CheckIssueApproved(issue)
- if err != nil {
- return errors.Wrap(err, "failed to check if issue is approved")
- }
- if !approved {
- return nil
- }
-
- var taskIDList []int
- var tasks []*store.TaskMessage
- stageTasks, err := r.store.ListTasks(ctx, &api.TaskFind{PipelineID: &activeStage.PipelineID, StageID: &activeStage.ID})
- if err != nil {
- return err
- }
- for _, task := range stageTasks {
- if task.Status == api.TaskPendingApproval {
- taskIDList = append(taskIDList, task.ID)
- tasks = append(tasks, task)
- }
- }
- if err := r.store.BatchPatchTaskStatus(ctx, taskIDList, api.TaskPending, externalApproval.ApproverUID); err != nil {
- return errors.Wrapf(err, "failed to update task status, task id list: %+v", taskIDList)
- }
- if err := r.activityManager.BatchCreateTaskStatusUpdateApprovalActivity(ctx, tasks, externalApproval.ApproverUID, issue, activeStage.Name); err != nil {
- return errors.Wrapf(err, "failed to create task status update activity")
- }
- return nil
- }(); err != nil {
- log.Error("failed to approve stage", zap.Error(err))
- continue
- }
-
- if _, err := r.store.UpdateExternalApprovalV2(ctx, &store.UpdateExternalApprovalMessage{
- // Archive external approval.
- ID: externalApproval.ID,
- RowStatus: api.Archived,
- }); err != nil {
- log.Error("failed to archive external apporval", zap.Error(err))
- continue
- }
- }
- case feishu.ApprovalStatusRejected:
- if err := func() error {
- payload := payload
- payload.Rejected = true
- bytes, err := json.Marshal(payload)
- if err != nil {
- return errors.Wrapf(err, "failed to marshal payload %+v", payload)
- }
- payloadString := string(bytes)
-
- if _, err := r.store.UpdateExternalApprovalV2(ctx, &store.UpdateExternalApprovalMessage{
- ID: externalApproval.ID,
- RowStatus: api.Normal,
- Payload: &payloadString,
- }); err != nil {
- return errors.Wrap(err, "failed to patch external approval")
- }
-
- stageName := "UNKNOWN"
- for _, stage := range stages {
- if stage.ID == payload.StageID {
- stageName = stage.Name
- break
- }
- }
- activityPayload, err := json.Marshal(api.ActivityIssueCommentCreatePayload{
- ExternalApprovalEvent: &api.ExternalApprovalEvent{
- Type: api.ExternalApprovalTypeFeishu,
- Action: api.ExternalApprovalEventActionReject,
- StageName: stageName,
- },
- })
- if err != nil {
- return errors.Wrap(err, "failed to marshal ActivityIssueExternalApprovalRejectPayload")
- }
-
- activityCreate := &store.ActivityMessage{
- CreatorUID: payload.AssigneeID,
- ContainerUID: issue.UID,
- Type: api.ActivityIssueCommentCreate,
- Level: api.ActivityInfo,
- Comment: "",
- Payload: string(activityPayload),
- }
-
- if _, err = r.activityManager.CreateActivity(ctx, activityCreate, &activity.Metadata{}); err != nil {
- return errors.Wrap(err, "failed to create activity after external approval rejected")
- }
- return nil
- }(); err != nil {
- log.Error("failed to handle rejected feishu approval", zap.Error(err))
- }
- }
- default:
- log.Error("Unknown ExternalApproval.Type", zap.Any("ExternalApproval", externalApproval))
- }
- }
- }()
- case <-ctx.Done():
- return
- }
- }
-}
-
-func (r *Runner) cancelOldExternalApprovalIfNeeded(ctx context.Context, issue *store.IssueMessage, stage *store.StageMessage, settingValue *api.SettingAppIMValue) (*store.ExternalApprovalMessage, error) {
- approval, err := r.store.GetExternalApprovalByIssueIDV2(ctx, issue.UID)
- if err != nil {
- return nil, err
- }
- if approval == nil {
- return nil, nil
- }
- var payload api.ExternalApprovalPayloadFeishu
- if err := json.Unmarshal([]byte(approval.Payload), &payload); err != nil {
- return nil, err
- }
-
- reason := api.ExternalApprovalCancelReasonGeneral
- cancelOld := func() bool {
- if payload.StageID != stage.ID {
- reason = api.ExternalApprovalCancelReasonNoTaskPendingApproval
- return true
- }
- if payload.AssigneeID != issue.Assignee.ID {
- reason = api.ExternalApprovalCancelReasonReassigned
- return true
- }
- pendingApprovalCount := 0
- tasks, err := r.store.ListTasks(ctx, &api.TaskFind{PipelineID: &stage.PipelineID, StageID: &stage.ID})
- if err != nil {
- log.Warn("apprun runner: failed to list tasks", zap.Int("issueID", issue.UID), zap.Error(err))
- return false
- }
- for _, task := range tasks {
- if task.Status == api.TaskPendingApproval {
- pendingApprovalCount++
- }
- }
- if pendingApprovalCount == 0 {
- reason = api.ExternalApprovalCancelReasonNoTaskPendingApproval
- return true
- }
- approved, err := utils.CheckIssueApproved(issue)
- if err != nil {
- log.Warn("apprun runner: failed to check if issue is approved", zap.Int("issueID", issue.UID), zap.Error(err))
- return false
- }
- if !approved {
- return true
- }
- return false
- }()
-
- if cancelOld {
- if _, err := r.store.UpdateExternalApprovalV2(ctx, &store.UpdateExternalApprovalMessage{ID: approval.ID, RowStatus: api.Archived}); err != nil {
- return nil, err
- }
- botID, err := r.p.GetBotID(ctx,
- feishu.TokenCtx{
- AppID: settingValue.AppID,
- AppSecret: settingValue.AppSecret,
- })
- if err != nil {
- return nil, err
- }
- if err := r.p.CancelExternalApproval(ctx,
- feishu.TokenCtx{
- AppID: settingValue.AppID,
- AppSecret: settingValue.AppSecret,
- },
- settingValue.ExternalApproval.ApprovalDefinitionID,
- payload.InstanceCode,
- payload.RequesterID,
- ); err != nil {
- return nil, err
- }
- if err := r.p.CreateExternalApprovalComment(ctx,
- feishu.TokenCtx{
- AppID: settingValue.AppID,
- AppSecret: settingValue.AppSecret,
- },
- payload.InstanceCode,
- botID,
- string(reason),
- ); err != nil {
- return nil, err
- }
- }
- return approval, nil
-}
-
-// CancelExternalApproval cancels the active external approval of an issue.
-func (r *Runner) CancelExternalApproval(ctx context.Context, issueID int, reason string) error {
- setting, err := r.store.GetAppIMApprovalSetting(ctx)
- if err != nil {
- return errors.Wrapf(err, "failed to get IM setting")
- }
- if setting == nil {
- return nil
- }
- if !setting.ExternalApproval.Enabled {
- return nil
- }
- approval, err := r.store.GetExternalApprovalByIssueIDV2(ctx, issueID)
- if err != nil {
- return err
- }
- if approval == nil {
- return nil
- }
- var payload api.ExternalApprovalPayloadFeishu
- if err := json.Unmarshal([]byte(approval.Payload), &payload); err != nil {
- return err
- }
- if _, err := r.store.UpdateExternalApprovalV2(ctx, &store.UpdateExternalApprovalMessage{ID: approval.ID, RowStatus: api.Archived}); err != nil {
- return err
- }
- botID, err := r.p.GetBotID(ctx,
- feishu.TokenCtx{
- AppID: setting.AppID,
- AppSecret: setting.AppSecret,
- })
- if err != nil {
- return err
- }
- if err := r.p.CancelExternalApproval(ctx,
- feishu.TokenCtx{
- AppID: setting.AppID,
- AppSecret: setting.AppSecret,
- },
- setting.ExternalApproval.ApprovalDefinitionID,
- payload.InstanceCode,
- payload.RequesterID,
- ); err != nil {
- return err
- }
- return r.p.CreateExternalApprovalComment(ctx,
- feishu.TokenCtx{
- AppID: setting.AppID,
- AppSecret: setting.AppSecret,
- },
- payload.InstanceCode,
- botID,
- reason,
- )
-}
-
-func (r *Runner) shouldCreateExternalApproval(ctx context.Context, issue *store.IssueMessage, stage *store.StageMessage, oldApproval *store.ExternalApprovalMessage) (bool, error) {
- approved, err := utils.CheckIssueApproved(issue)
- if err != nil {
- return false, errors.Wrap(err, "failed to check if issue is approved")
- }
- if !approved {
- return false, nil
- }
-
- policy, err := r.store.GetPipelineApprovalPolicy(ctx, stage.EnvironmentID)
- if err != nil {
- return false, err
- }
- // don't send approvals for auto-approval stages.
- if policy.Value == api.PipelineApprovalValueManualNever {
- return false, nil
- }
- if oldApproval != nil {
- var oldPayload api.ExternalApprovalPayloadFeishu
- if err := json.Unmarshal([]byte(oldApproval.Payload), &oldPayload); err != nil {
- return false, err
- }
- // nothing changes
- if oldPayload.StageID == stage.ID && oldPayload.AssigneeID == issue.Assignee.ID {
- return false, nil
- }
- }
- pendingApprovalCount := 0
- tasks, err := r.store.ListTasks(ctx, &api.TaskFind{PipelineID: &stage.PipelineID, StageID: &stage.ID})
- if err != nil {
- return false, err
- }
- taskCheckRuns, err := r.store.ListTaskCheckRuns(ctx, &store.TaskCheckRunFind{PipelineID: &stage.PipelineID, StageID: &stage.ID})
- if err != nil {
- return false, err
- }
-
- for _, task := range tasks {
- if task.Status == api.TaskPendingApproval {
- pendingApprovalCount++
- }
-
- instance, err := r.store.GetInstanceV2(ctx, &store.FindInstanceMessage{UID: &task.InstanceID, ShowDeleted: false})
- if err != nil {
- return false, err
- }
- if instance == nil {
- return false, nil
- }
- if err := r.licenseService.IsFeatureEnabledForInstance(api.FeatureIMApproval, instance); err != nil {
- log.Debug(err.Error(), zap.String("instance", instance.ResourceID))
- return false, nil
- }
-
- ok, err := utils.PassAllCheck(task, api.TaskCheckStatusSuccess, taskCheckRuns, instance.Engine)
- if err != nil {
- return false, err
- }
- if !ok {
- return false, nil
- }
- }
- if pendingApprovalCount == 0 {
- return false, nil
- }
- return true, nil
-}
-
-func (r *Runner) createExternalApproval(ctx context.Context, issue *store.IssueMessage, stage *store.StageMessage, settingValue *api.SettingAppIMValue) error {
- users, err := r.p.GetIDByEmail(ctx,
- feishu.TokenCtx{
- AppID: settingValue.AppID,
- AppSecret: settingValue.AppSecret,
- },
- []string{issue.Creator.Email, issue.Assignee.Email})
- if err != nil {
- return err
- }
- // assignee who approves the external approval is a must-have, so we returns error if we failed to find the user id.
- if _, ok := users[issue.Assignee.Email]; !ok {
- return errors.Errorf("failed to get user_id for issue assignee, email: %s", issue.Assignee.Email)
- }
- // if the creator is not found, the application bot will represent the creator.
- if _, ok := users[issue.Creator.Email]; !ok {
- botID, err := r.p.GetBotID(ctx, feishu.TokenCtx{
- AppID: settingValue.AppID,
- AppSecret: settingValue.AppSecret,
- })
- if err != nil {
- return errors.WithStack(err)
- }
- users[issue.Creator.Email] = botID
- }
-
- var taskList []feishu.Task
- tasks, err := r.store.ListTasks(ctx, &api.TaskFind{PipelineID: &stage.PipelineID, StageID: &stage.ID})
- if err != nil {
- return err
- }
- for _, task := range tasks {
- taskList = append(taskList, feishu.Task{
- Name: task.Name,
- Status: string(task.Status),
- })
- }
-
- for i, task := range tasks {
- statement, err := utils.GetTaskStatement(task.Payload)
- if err != nil {
- return err
- }
- if statement == "" {
- continue
- }
- taskList[i].Statement = statement
- }
-
- setting, err := r.store.GetWorkspaceGeneralSetting(ctx)
- if err != nil {
- return errors.Wrapf(err, "failed to get workspace setting")
- }
-
- instanceCode, err := r.p.CreateExternalApproval(ctx,
- feishu.TokenCtx{
- AppID: settingValue.AppID,
- AppSecret: settingValue.AppSecret,
- },
- feishu.Content{
- Issue: fmt.Sprintf("#%d %s", issue.UID, issue.Title),
- Stage: stage.Name,
- Link: fmt.Sprintf("%s/issue/%s-%d", setting.ExternalUrl, slug.Make(issue.Title), issue.UID),
- TaskList: taskList,
- },
- settingValue.ExternalApproval.ApprovalDefinitionID,
- users[issue.Creator.Email],
- users[issue.Assignee.Email])
- if err != nil {
- return err
- }
- payload := api.ExternalApprovalPayloadFeishu{
- StageID: stage.ID,
- AssigneeID: issue.Assignee.ID,
- InstanceCode: instanceCode,
- RequesterID: users[issue.Creator.Email],
- Rejected: false,
- }
- b, err := json.Marshal(payload)
- if err != nil {
- return err
- }
- if _, err := r.store.CreateExternalApprovalV2(ctx, &store.ExternalApprovalMessage{
- IssueUID: issue.UID,
- ApproverUID: issue.Assignee.ID,
- RequesterUID: issue.Creator.ID,
- Type: api.ExternalApprovalTypeFeishu,
- Payload: string(b),
- }); err != nil {
- return err
- }
- return nil
-}
-
-// scheduleApproval tries to cancel old external apporvals and create new external approvals if needed.
-func (r *Runner) scheduleApproval(ctx context.Context, issue *store.IssueMessage, stages []*store.StageMessage, settingValue *api.SettingAppIMValue) {
- if !settingValue.ExternalApproval.Enabled {
- return
- }
-
- if settingValue.ExternalApproval.ApprovalDefinitionID == "" {
- log.Error("no approval code", zap.Any("settingValue", settingValue))
- return
- }
-
- activeStage := utils.GetActiveStage(stages)
- if activeStage == nil {
- return
- }
-
- oldApproval, err := r.cancelOldExternalApprovalIfNeeded(ctx, issue, activeStage, settingValue)
- if err != nil {
- log.Error("failed to cancelOldExternalApprovalIfNeeded", zap.Error(err))
- return
- }
-
- // createExternalApprovalIfNeeded
- // check if we need to create a new external approval
- // 1. the approval policy of the stage environment is MANUAL_APPROVAL_ALWAYS.
- // 2. the stage has one or more PENDING_APPROVAL tasks.
- // 3. all task checks of the stage are done and the results have no errors.
- // 4. the issue is approved.
- ok, err := r.shouldCreateExternalApproval(ctx, issue, activeStage, oldApproval)
- if err != nil {
- log.Error("failed to check shouldCreateExternalApproval", zap.Error(err))
- return
- }
- if !ok {
- return
- }
-
- if err := r.createExternalApproval(ctx, issue, activeStage, settingValue); err != nil {
- log.Error("failed to create external approval", zap.Error(err))
- return
- }
-}
-
-// tryUpdateApprovalDefinition is run on application runner start.
-// The approval definition may have changed so we make idempotent POST request to patch the definition.
-func (r *Runner) tryUpdateApprovalDefinition(ctx context.Context) error {
- setting, err := r.store.GetAppIMApprovalSetting(ctx)
- if err != nil {
- return errors.Wrapf(err, "failed to get IM setting")
- }
- if setting == nil {
- return nil
- }
- if !setting.ExternalApproval.Enabled {
- return nil
- }
- // pass in ApprovalDefinitionID so that this would be a PATCH.
- if _, err := r.p.CreateApprovalDefinition(ctx, feishu.TokenCtx{
- AppID: setting.AppID,
- AppSecret: setting.AppSecret,
- }, setting.ExternalApproval.ApprovalDefinitionID); err != nil {
- return errors.Wrap(err, "failed to update approval definition")
- }
- return nil
-}
diff --git a/backend/runner/taskrun/scheduler.go b/backend/runner/taskrun/scheduler.go
index 20e2935d5e..6fca3ada7e 100644
--- a/backend/runner/taskrun/scheduler.go
+++ b/backend/runner/taskrun/scheduler.go
@@ -24,7 +24,6 @@ import (
api "github.com/bytebase/bytebase/backend/legacyapi"
metricAPI "github.com/bytebase/bytebase/backend/metric"
"github.com/bytebase/bytebase/backend/plugin/metric"
- "github.com/bytebase/bytebase/backend/runner/apprun"
"github.com/bytebase/bytebase/backend/runner/metricreport"
"github.com/bytebase/bytebase/backend/runner/schemasync"
"github.com/bytebase/bytebase/backend/store"
@@ -61,7 +60,6 @@ var (
// NewScheduler creates a new task scheduler.
func NewScheduler(
store *store.Store,
- applicationRunner *apprun.Runner,
schemaSyncer *schemasync.Syncer,
activityManager *activity.Manager,
licenseService enterpriseAPI.LicenseService,
@@ -69,29 +67,27 @@ func NewScheduler(
profile config.Profile,
metricReporter *metricreport.Reporter) *Scheduler {
return &Scheduler{
- store: store,
- applicationRunner: applicationRunner,
- schemaSyncer: schemaSyncer,
- activityManager: activityManager,
- licenseService: licenseService,
- profile: profile,
- stateCfg: stateCfg,
- executorMap: make(map[api.TaskType]Executor),
- metricReporter: metricReporter,
+ store: store,
+ schemaSyncer: schemaSyncer,
+ activityManager: activityManager,
+ licenseService: licenseService,
+ profile: profile,
+ stateCfg: stateCfg,
+ executorMap: make(map[api.TaskType]Executor),
+ metricReporter: metricReporter,
}
}
// Scheduler is the task scheduler.
type Scheduler struct {
- store *store.Store
- applicationRunner *apprun.Runner
- schemaSyncer *schemasync.Syncer
- activityManager *activity.Manager
- licenseService enterpriseAPI.LicenseService
- stateCfg *state.State
- profile config.Profile
- executorMap map[api.TaskType]Executor
- metricReporter *metricreport.Reporter
+ store *store.Store
+ schemaSyncer *schemasync.Syncer
+ activityManager *activity.Manager
+ licenseService enterpriseAPI.LicenseService
+ stateCfg *state.State
+ profile config.Profile
+ executorMap map[api.TaskType]Executor
+ metricReporter *metricreport.Reporter
}
// Register will register a task executor factory.
@@ -377,9 +373,6 @@ func (s *Scheduler) PatchTask(ctx context.Context, task *store.TaskMessage, task
return errors.Errorf("database schema ID not found %v", task.DatabaseID)
}
// it's ok to fail.
- if err := s.applicationRunner.CancelExternalApproval(ctx, issue.UID, api.ExternalApprovalCancelReasonSQLModified); err != nil {
- log.Error("failed to cancel external approval on SQL modified", zap.Int("issue_id", issue.UID), zap.Error(err))
- }
s.stateCfg.IssueExternalApprovalRelayCancelChan <- issue.UID
if taskPatched.Type == api.TaskDatabaseSchemaUpdateGhostSync {
if err := s.store.CreateTaskCheckRun(ctx, &store.TaskCheckRunMessage{
@@ -1166,14 +1159,6 @@ func (s *Scheduler) ChangeIssueStatus(ctx context.Context, issue *store.IssueMes
return errors.Wrapf(err, "failed to update issue %q's status", issue.Title)
}
- // Cancel external approval, it's ok if we failed.
- if newStatus != api.IssueOpen {
- if err := s.applicationRunner.CancelExternalApproval(ctx, issue.UID, api.ExternalApprovalCancelReasonIssueNotOpen); err != nil {
- log.Error("failed to cancel external approval on issue cancellation or completion", zap.Error(err))
- }
- s.stateCfg.IssueExternalApprovalRelayCancelChan <- issue.UID
- }
-
payload, err := json.Marshal(api.ActivityIssueStatusUpdatePayload{
OldStatus: issue.Status,
NewStatus: newStatus,
@@ -1276,14 +1261,6 @@ func (s *Scheduler) onTaskStatusPatched(ctx context.Context, issue *store.IssueM
}
}
- // every task in the stage completes
- // cancel external approval, it's ok if we failed.
- if !taskStage.Active {
- if err := s.applicationRunner.CancelExternalApproval(ctx, issue.UID, api.ExternalApprovalCancelReasonNoTaskPendingApproval); err != nil {
- log.Error("failed to cancel external approval on stage tasks completion", zap.Int("issue_id", issue.UID), zap.Error(err))
- }
- }
-
// every task in the stage terminated
// create "stage ends" activity.
if stageTaskAllTerminated {
diff --git a/backend/server/issue.go b/backend/server/issue.go
index 179d8af399..b97a672435 100644
--- a/backend/server/issue.go
+++ b/backend/server/issue.go
@@ -282,12 +282,6 @@ func (s *Server) registerIssueRoutes(g *echo.Group) {
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to update issue with ID %d", id)).SetInternal(err)
}
- // cancel external approval on assignee change
- if issuePatch.AssigneeID != nil {
- if err := s.ApplicationRunner.CancelExternalApproval(ctx, issue.UID, api.ExternalApprovalCancelReasonReassigned); err != nil {
- log.Error("failed to cancel external approval on assignee change", zap.Int("issue_id", issue.UID), zap.Error(err))
- }
- }
payloadList := [][]byte{}
if issuePatch.Name != nil && *issuePatch.Name != issue.Title {
diff --git a/backend/server/server.go b/backend/server/server.go
index dcbd9cba27..5210d2af0e 100644
--- a/backend/server/server.go
+++ b/backend/server/server.go
@@ -69,7 +69,6 @@ import (
"github.com/bytebase/bytebase/backend/resources/postgres"
"github.com/bytebase/bytebase/backend/runner/anomaly"
"github.com/bytebase/bytebase/backend/runner/approval"
- "github.com/bytebase/bytebase/backend/runner/apprun"
"github.com/bytebase/bytebase/backend/runner/backuprun"
"github.com/bytebase/bytebase/backend/runner/mail"
"github.com/bytebase/bytebase/backend/runner/metricreport"
@@ -167,7 +166,6 @@ type Server struct {
MailSender *mail.SlowQueryWeeklyMailSender
BackupRunner *backuprun.Runner
AnomalyScanner *anomaly.Scanner
- ApplicationRunner *apprun.Runner
RollbackRunner *rollbackrun.Runner
ApprovalRunner *approval.Runner
RelayRunner *relay.Runner
@@ -467,7 +465,6 @@ func NewServer(ctx context.Context, profile config.Profile) (*Server, error) {
s.SlowQuerySyncer = slowquerysync.NewSyncer(storeInstance, s.dbFactory, s.stateCfg, profile)
// TODO(p0ny): enable Feishu provider only when it is needed.
s.feishuProvider = feishu.NewProvider(profile.FeishuAPIURL)
- s.ApplicationRunner = apprun.NewRunner(storeInstance, s.ActivityManager, s.feishuProvider, profile, s.licenseService)
s.BackupRunner = backuprun.NewRunner(storeInstance, s.dbFactory, s.s3Client, s.stateCfg, &profile)
s.TaskSchedulerV2 = taskrun.NewSchedulerV2(storeInstance, s.stateCfg, s.ActivityManager)
@@ -483,7 +480,7 @@ func NewServer(ctx context.Context, profile config.Profile) (*Server, error) {
s.TaskSchedulerV2.Register(api.TaskDatabaseRestorePITRRestore, taskrun.NewPITRRestoreExecutor(storeInstance, s.dbFactory, s.s3Client, s.SchemaSyncer, s.stateCfg, profile))
s.TaskSchedulerV2.Register(api.TaskDatabaseRestorePITRCutover, taskrun.NewPITRCutoverExecutor(storeInstance, s.dbFactory, s.SchemaSyncer, s.BackupRunner, s.ActivityManager, profile))
- s.TaskScheduler = taskrun.NewScheduler(storeInstance, s.ApplicationRunner, s.SchemaSyncer, s.ActivityManager, s.licenseService, s.stateCfg, profile, s.MetricReporter)
+ s.TaskScheduler = taskrun.NewScheduler(storeInstance, s.SchemaSyncer, s.ActivityManager, s.licenseService, s.stateCfg, profile, s.MetricReporter)
s.TaskScheduler.Register(api.TaskGeneral, taskrun.NewDefaultExecutor())
s.TaskScheduler.Register(api.TaskDatabaseCreate, taskrun.NewDatabaseCreateExecutor(storeInstance, s.dbFactory, s.SchemaSyncer, profile))
s.TaskScheduler.Register(api.TaskDatabaseSchemaBaseline, taskrun.NewSchemaBaselineExecutor(storeInstance, s.dbFactory, s.ActivityManager, s.licenseService, s.stateCfg, s.SchemaSyncer, profile))
@@ -1009,8 +1006,6 @@ func (s *Server) Run(ctx context.Context, port int) error {
s.runnerWG.Add(1)
go s.AnomalyScanner.Run(ctx, &s.runnerWG)
s.runnerWG.Add(1)
- go s.ApplicationRunner.Run(ctx, &s.runnerWG)
- s.runnerWG.Add(1)
go s.RollbackRunner.Run(ctx, &s.runnerWG)
s.runnerWG.Add(1)
go s.ApprovalRunner.Run(ctx, &s.runnerWG)