Skip to content

Commit

Permalink
minor changes
Browse files Browse the repository at this point in the history
Signed-off-by: Min Min <[email protected]>
  • Loading branch information
jamsman94 committed Apr 19, 2022
1 parent 181c136 commit 33d1864
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
16 changes: 14 additions & 2 deletions pkg/microservice/aslan/core/common/service/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ limitations under the License.
package service

import (
"encoding/json"
"fmt"
workflow2 "github.com/koderover/zadig/pkg/microservice/aslan/core/workflow/service/workflow"
"sync"

"github.com/hashicorp/go-multierror"
Expand All @@ -30,6 +30,7 @@ import (
"github.com/koderover/zadig/pkg/microservice/aslan/core/common/repository/mongodb/template"
"github.com/koderover/zadig/pkg/microservice/aslan/core/common/service/collaboration"
"github.com/koderover/zadig/pkg/microservice/aslan/core/common/service/gerrit"
"github.com/koderover/zadig/pkg/microservice/aslan/core/common/service/nsq"
"github.com/koderover/zadig/pkg/microservice/aslan/core/common/service/webhook"
"github.com/koderover/zadig/pkg/setting"
"github.com/koderover/zadig/pkg/shared/client/systemconfig"
Expand Down Expand Up @@ -99,7 +100,7 @@ func DeleteWorkflow(workflowName, requestID string, isDeletingProductTmpl bool,
log.Errorf("Failed to process webhook, err: %s", err)
}

err = workflow2.DisableCronjobForWorkflow(workflow)
err = DisableCronjobForWorkflow(workflow)
if err != nil {
log.Errorf("Failed to stop cronjob for workflow: %s, error: %s", workflow.Name, err)
}
Expand Down Expand Up @@ -160,6 +161,17 @@ func DeleteWorkflow(workflowName, requestID string, isDeletingProductTmpl bool,
return nil
}

func DisableCronjobForWorkflow(workflow *models.Workflow) error {
payload := &CronjobPayload{
Name: workflow.Name,
JobType: config.WorkflowCronjob,
Action: setting.TypeDisableCronjob,
}

pl, _ := json.Marshal(payload)
return nsq.Publish(setting.TopicCronjob, pl)
}

func ProcessWebhook(updatedHooks, currentHooks interface{}, name string, logger *zap.SugaredLogger) error {
currentSet := toHookSet(currentHooks)
updatedSet := toHookSet(updatedHooks)
Expand Down
13 changes: 1 addition & 12 deletions pkg/microservice/aslan/core/workflow/service/workflow/cronjob.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,6 @@ func HandleCronjob(workflow *commonmodels.Workflow, log *zap.SugaredLogger) erro
return nil
}

func DisableCronjobForWorkflow(workflow *commonmodels.Workflow) error {
payload := &commonservice.CronjobPayload{
Name: workflow.Name,
JobType: config.WorkflowCronjob,
Action: setting.TypeDisableCronjob,
}

pl, _ := json.Marshal(payload)
return nsq.Publish(setting.TopicCronjob, pl)
}

func UpdateCronjob(parentName, parentType, productName string, schedule *commonmodels.ScheduleCtrl, log *zap.SugaredLogger) (deleteList []string, err error) {
idMap := make(map[string]bool)
deleteList = make([]string, 0)
Expand Down Expand Up @@ -146,7 +135,7 @@ func UpdateCronjob(parentName, parentType, productName string, schedule *commonm
return deleteList, nil
}

func DeleteCronjob(parentName, parentType string, log *zap.SugaredLogger) error {
func DeleteCronjob(parentName, parentType string) error {
return commonrepo.NewCronjobColl().Delete(&commonrepo.CronjobDeleteOption{
ParentName: parentName,
ParentType: parentType,
Expand Down

0 comments on commit 33d1864

Please sign in to comment.