本文整理汇总了Golang中github.com/arteev/dsql/rdb/action.Context.IncInt方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.IncInt方法的具体用法?Golang Context.IncInt怎么用?Golang Context.IncInt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/arteev/dsql/rdb/action.Context
的用法示例。
在下文中一共展示了Context.IncInt方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: runItem
func runItem(d db.Database, s *sqlcommand.SQLCommand, doaction action.Actioner, ctx *action.Context, pget parametergetter.ParameterGetter) error {
logger.Trace.Println("runItem")
defer logger.Trace.Println(d.Code, "runItem done")
if s != nil {
logger.Trace.Println(d.Code, s.Script)
}
wg.Add(1)
ctx.IncInt("exec", 1)
params := ctx.Get("Params").([]parameters.Parameter)
go func() {
timeout := ctx.GetDef("timeout", 0).(int)
defer wg.Done()
var (
ctxExec context.Context
cancel context.CancelFunc
)
ch := make(chan bool)
if timeout > 0 {
ctxExec, cancel = context.WithTimeout(context.Background(), time.Duration(timeout)*time.Second)
} else {
ctxExec, cancel = context.WithCancel(context.Background())
}
defer cancel()
localCtx := action.NewContext()
go func() {
defer func() {
ch <- true
close(ch)
}()
ctx.Set("context"+d.Code, localCtx)
ctx.Set("iscancel", ch)
localCtx.Snap.Start()
localCtx.Set("success", false)
connectionString, e := paramsreplace.Replace(d.ConnectionString, params)
if e != nil {
ctx.IncInt("failed", 1)
logger.Error.Println(e)
return
}
logger.Debug.Println(d.Code, "Connection string:", connectionString)
connection, err := rdb.Open(d.Engine, connectionString)
if err != nil {
ctx.IncInt("failed", 1)
logger.Error.Println(d.Code, err)
return
}
defer func() {
if err := connection.Close(); err != nil {
panic(err)
} else {
logger.Trace.Printf("%s disconnected", d.Code)
}
}()
err = doaction(d, connection, s, ctx)
if err != nil {
if err.Error() != "cancel" {
ctx.IncInt("failed", 1)
localCtx.Snap.Done(err)
logger.Error.Println(d.Code, err)
if !ctx.GetDef("silent", false).(bool) {
fmt.Fprintf(os.Stdout, "%s: %s\n", d.Code, strings.Replace(err.Error(), "\n", " ", -1))
}
}
return
}
localCtx.Set("success", true)
ctx.IncInt("success", 1)
localCtx.Snap.Done(nil)
runtime.Gosched()
}()
select {
case <-ch:
logger.Trace.Println("operation done w/o timeout")
return
case <-ctxExec.Done():
err := ctxExec.Err()
logger.Trace.Printf("operation done: %s\n", err)
ctx.IncInt("failed", 1)
localCtx.Snap.Done(err)
logger.Error.Println(d.Code, err)
// ch <- true
return
}
//.........这里部分代码省略.........