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 <yinw@vmware.com>
This commit is contained in:
Wenkai Yin 2020-03-26 23:12:02 +08:00
parent 213c534e8a
commit 9a92b9e725
2 changed files with 5 additions and 3 deletions

View File

@ -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{

View File

@ -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)