當前位置: 首頁>>代碼示例>>Golang>>正文


Golang retry.CallArgs類代碼示例

本文整理匯總了Golang中github.com/juju/retry.CallArgs的典型用法代碼示例。如果您正苦於以下問題:Golang CallArgs類的具體用法?Golang CallArgs怎麽用?Golang CallArgs使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了CallArgs類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: dialAndLogin

// dialAndLogin returns a mongo session logged in as a user with administrative
// privileges
func dialAndLogin(mongoInfo *mongo.MongoInfo, callArgs retry.CallArgs) (mgoSession, mgoDb, error) {
	var session *mgo.Session
	opts := mongo.DefaultDialOpts()
	callArgs.Func = func() error {
		// Try to connect, retry a few times until the db comes up.
		var err error
		session, err = mongo.DialWithInfo(mongoInfo.Info, opts)
		if err == nil {
			return nil
		}
		logger.Errorf("cannot open mongo connection: %v", err)
		return err
	}
	if err := retry.Call(callArgs); err != nil {
		return nil, nil, errors.Annotate(err, "error dialing mongo to resume HA")
	}
	admin := session.DB("admin")
	if mongoInfo.Tag != nil {
		if err := admin.Login(mongoInfo.Tag.String(), mongoInfo.Password); err != nil {
			return nil, nil, errors.Annotatef(err, "cannot log in to admin database as %q", mongoInfo.Tag)
		}
	} else if mongoInfo.Password != "" {
		if err := admin.Login(mongo.AdminUser, mongoInfo.Password); err != nil {
			return nil, nil, errors.Annotate(err, "cannot log in to admin database")
		}
	}
	return session, admin, nil
}
開發者ID:makyo,項目名稱:juju,代碼行數:30,代碼來源:upgrade_mongo.go

示例2: mongoDumpCall

func mongoDumpCall(
	runCommand utilsRun, tmpDir, mongoPath, adminPassword, migrationName string,
	statePort int, callArgs retry.CallArgs,
) (string, error) {
	mongodump := filepath.Join(mongoPath, "mongodump")
	dumpParams := []string{
		"--ssl",
		"-u", "admin",
		"-p", adminPassword,
		"--port", strconv.Itoa(statePort),
		"--host", "localhost",
		"--out", filepath.Join(tmpDir, fmt.Sprintf("migrateTo%sdump", migrationName)),
	}
	var out string
	callArgs.Func = func() error {
		var err error
		out, err = runCommand(mongodump, dumpParams...)
		if err == nil {
			return nil
		}
		logger.Errorf("cannot dump db %v: %s", err, out)
		return err
	}
	if err := retry.Call(callArgs); err != nil {
		logger.Errorf(out)
		return out, errors.Annotate(err, "cannot dump mongo db")
	}
	return out, nil
}
開發者ID:makyo,項目名稱:juju,代碼行數:29,代碼來源:upgrade_mongo.go

示例3: TestCallArgsDefaults

func (*retrySuite) TestCallArgsDefaults(c *gc.C) {
	// BackoffFactor is one of the two values with reasonable
	// defaults, and the default is linear if not specified.
	// The other default is the Clock. If not specified, it is the
	// wall clock.
	args := retry.CallArgs{
		Func:     func() error { return errors.New("bah") },
		Attempts: 5,
		Delay:    time.Minute,
	}

	err := args.Validate()
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(args.BackoffFactor, gc.Equals, float64(1))
	c.Assert(args.Clock, gc.Equals, clock.WallClock)
}
開發者ID:howbazaar,項目名稱:retry-poc,代碼行數:16,代碼來源:retry_test.go


注:本文中的github.com/juju/retry.CallArgs類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。