Merge pull request #474 from ywk253100/dev

support job retrying
This commit is contained in:
Wenkai Yin 2016-07-05 12:05:57 +08:00 committed by GitHub
commit 71a60fca74
4 changed files with 59 additions and 29 deletions

View File

@ -1,23 +0,0 @@
/*
Copyright (c) 2016 VMware, Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package error
// RetryChecker checks whether a job should retry if encounters an error
type RetryChecker interface {
// Retry : if the error can be disappear after retrying the job, Retry
// returns true
Retry(error) bool
}

View File

@ -74,6 +74,17 @@ func (d *Deleter) Exit() error {
// Enter deletes repository or tags // Enter deletes repository or tags
func (d *Deleter) Enter() (string, error) { func (d *Deleter) Enter() (string, error) {
state, err := d.enter()
if err != nil && retry(err) {
d.logger.Info("waiting for retrying...")
return models.JobRetrying, nil
}
return state, err
}
func (d *Deleter) enter() (string, error) {
if len(d.tags) == 0 { if len(d.tags) == 0 {
tags, err := d.dstClient.ListTag() tags, err := d.dstClient.ListTag()

View File

@ -19,12 +19,10 @@ import (
"net" "net"
) )
// ReplicaRetryChecker determines whether a job should be retried when an error occurred func retry(err error) bool {
type ReplicaRetryChecker struct { if err == nil {
return false
} }
// Retry ...
func (r *ReplicaRetryChecker) Retry(err error) bool {
return isTemporary(err) return isTemporary(err)
} }

View File

@ -152,6 +152,17 @@ type Checker struct {
// Enter check existence of project, if it does not exist, create it, // Enter check existence of project, if it does not exist, create it,
// if it exists, check whether the user has write privilege to it. // if it exists, check whether the user has write privilege to it.
func (c *Checker) Enter() (string, error) { func (c *Checker) Enter() (string, error) {
state, err := c.enter()
if err != nil && retry(err) {
c.logger.Info("waiting for retrying...")
return models.JobRetrying, nil
}
return state, err
}
func (c *Checker) enter() (string, error) {
enter: enter:
exist, canWrite, err := c.projectExist() exist, canWrite, err := c.projectExist()
if err != nil { if err != nil {
@ -316,6 +327,17 @@ type ManifestPuller struct {
// Enter pulls manifest of a tag and checks if all blobs exist in the destination registry // Enter pulls manifest of a tag and checks if all blobs exist in the destination registry
func (m *ManifestPuller) Enter() (string, error) { func (m *ManifestPuller) Enter() (string, error) {
state, err := m.enter()
if err != nil && retry(err) {
m.logger.Info("waiting for retrying...")
return models.JobRetrying, nil
}
return state, err
}
func (m *ManifestPuller) enter() (string, error) {
if len(m.tags) == 0 { if len(m.tags) == 0 {
m.logger.Infof("no tag needs to be replicated, next state is \"finished\"") m.logger.Infof("no tag needs to be replicated, next state is \"finished\"")
return models.JobFinished, nil return models.JobFinished, nil
@ -389,6 +411,17 @@ type BlobTransfer struct {
// Enter pulls blobs and then pushs them to destination registry. // Enter pulls blobs and then pushs them to destination registry.
func (b *BlobTransfer) Enter() (string, error) { func (b *BlobTransfer) Enter() (string, error) {
state, err := b.enter()
if err != nil && retry(err) {
b.logger.Info("waiting for retrying...")
return models.JobRetrying, nil
}
return state, err
}
func (b *BlobTransfer) enter() (string, error) {
name := b.repository name := b.repository
tag := b.tags[0] tag := b.tags[0]
for _, blob := range b.blobs { for _, blob := range b.blobs {
@ -417,6 +450,17 @@ type ManifestPusher struct {
// exists, pushs it to destination registry. The checking operation is to avoid // exists, pushs it to destination registry. The checking operation is to avoid
// the situation that the tag is deleted during the blobs transfering // the situation that the tag is deleted during the blobs transfering
func (m *ManifestPusher) Enter() (string, error) { func (m *ManifestPusher) Enter() (string, error) {
state, err := m.enter()
if err != nil && retry(err) {
m.logger.Info("waiting for retrying...")
return models.JobRetrying, nil
}
return state, err
}
func (m *ManifestPusher) enter() (string, error) {
name := m.repository name := m.repository
tag := m.tags[0] tag := m.tags[0]
_, exist, err := m.srcClient.ManifestExist(tag) _, exist, err := m.srcClient.ManifestExist(tag)