当前位置: 首页>>代码示例>>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;未经允许,请勿转载。