本文整理汇总了Golang中github.com/juju/retry.CallArgs.Func方法的典型用法代码示例。如果您正苦于以下问题:Golang CallArgs.Func方法的具体用法?Golang CallArgs.Func怎么用?Golang CallArgs.Func使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/juju/retry.CallArgs
的用法示例。
在下文中一共展示了CallArgs.Func方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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
}
示例2: 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
}