From 9a92b9e725fd3e1c56eb494b476690853f21de3c Mon Sep 17 00:00:00 2001 From: Wenkai Yin Date: Thu, 26 Mar 2020 23:12:02 +0800 Subject: [PATCH] Fix bugs of replication 1. Bump up the version of API used in replicatoin scheduler job 2. Check the error message to determine whether the job exists or not in jobservice when unschedule a job Signed-off-by: Wenkai Yin --- src/jobservice/job/impl/replication/scheduler.go | 3 ++- src/replication/policy/scheduler/scheduler.go | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/jobservice/job/impl/replication/scheduler.go b/src/jobservice/job/impl/replication/scheduler.go index 95889bc65..6539117af 100644 --- a/src/jobservice/job/impl/replication/scheduler.go +++ b/src/jobservice/job/impl/replication/scheduler.go @@ -19,6 +19,7 @@ import ( "net/http" "os" + "github.com/goharbor/harbor/src/common/api" common_http "github.com/goharbor/harbor/src/common/http" "github.com/goharbor/harbor/src/common/http/modifier/auth" "github.com/goharbor/harbor/src/jobservice/job" @@ -56,7 +57,7 @@ func (s *Scheduler) Run(ctx job.Context, params job.Parameters) error { logger := ctx.GetLogger() url := params["url"].(string) - url = fmt.Sprintf("%s/api/replication/executions?trigger=%s", url, model.TriggerTypeScheduled) + url = fmt.Sprintf("%s/api/%s/replication/executions?trigger=%s", url, api.APIVersion, model.TriggerTypeScheduled) policyID := (int64)(params["policy_id"].(float64)) cred := auth.NewSecretAuthorizer(os.Getenv("JOBSERVICE_SECRET")) client := common_http.NewClient(&http.Client{ diff --git a/src/replication/policy/scheduler/scheduler.go b/src/replication/policy/scheduler/scheduler.go index 421d5938b..11c9dc3b3 100644 --- a/src/replication/policy/scheduler/scheduler.go +++ b/src/replication/policy/scheduler/scheduler.go @@ -16,7 +16,7 @@ package scheduler import ( "fmt" - "net/http" + "strings" "time" commonHttp "github.com/goharbor/harbor/src/common/http" @@ -104,7 +104,8 @@ func (s *scheduler) Unschedule(policyID int64) error { if err = s.jobservice.PostAction(sj.JobID, job.JobActionStop); err != nil { // if the job specified by jobID is not found in jobservice, just delete // the record from database - if e, ok := err.(*commonHttp.Error); !ok || e.Code != http.StatusNotFound { + if e, ok := err.(*commonHttp.Error); !ok || + !strings.Contains(e.Message, "no valid periodic job policy found") { return err } log.Debugf("the stop action for schedule job %s submitted to the jobservice", sj.JobID)