Commit fce7640c authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 85fdae69
......@@ -21,11 +21,11 @@
package task
import (
"context"
"fmt"
"context"
"fmt"
taskctx "lab.nexedi.com/kirr/neo/go/internal/xcontext/task"
"lab.nexedi.com/kirr/neo/go/internal/log"
taskctx "lab.nexedi.com/kirr/neo/go/internal/xcontext/task"
"lab.nexedi.com/kirr/neo/go/internal/log"
)
// Running is syntactic sugar to push new task to operational stack, log it and
......@@ -35,34 +35,28 @@ import (
//
// defer task.Running(&ctx, "my task")(&err)
func Running(ctxp *context.Context, name string) func(*error) {
return running(ctxp, name)
return running(ctxp, name)
}
// Runningf is Running cousin with formatting support
func Runningf(ctxp *context.Context, format string, argv ...interface{}) func(*error) {
return running(ctxp, fmt.Sprintf(format, argv...))
return running(ctxp, fmt.Sprintf(format, argv...))
}
func running(ctxp *context.Context, name string) func(*error) {
ctx := taskctx.Running(*ctxp, name)
*ctxp = ctx
log.Depth(2).Info(ctx, "start") // XXX log -> trace
return func(errp *error) {
if *errp != nil {
// XXX is it good idea to log to error here? (not in above layer)
// XXX what is error here could be not so error above
// XXX or we still want to log all errors - right?
//
// -> yes, we do want to trace unconditionally when a task is finished
// here it is tracing, just with trace sink being hardcoded to log.
log.Depth(1).Warning(ctx, "## ", *errp) // XXX "##" temp
} else {
log.Depth(1).Info(ctx, "done")
}
// NOTE not *ctxp here - as context pointed by ctxp could be
// changed when this deferred function is run
taskctx.ErrContext(errp, ctx)
}
ctx := taskctx.Running(*ctxp, name)
*ctxp = ctx
log.Depth(2).Info(ctx, "[") // XXX log -> trace, don't put ":" before "["
return func(errp *error) {
err := ""
if e := *errp; e != nil {
err = fmt.Sprintf(" (%s)", e)
}
log.Depth(1).Info(ctx, "]" + err) // XXX log -> trace, don't put ":" before "]"
// NOTE not *ctxp here - as context pointed by ctxp could be
// changed when this deferred function is run
taskctx.ErrContext(errp, ctx)
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment