You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This works well enough, but the "docker-service" would be better expressed as a dependency. It should also be possible to have multiple concurrent tasks that depend on this.
I think it would be great if we could do something like this:
version: '3'
tasks:
with-docker-service:
cmds:
- docker compose up ...
- defer-dep: docker compose down ... # similar to `defer`, but only executes after all tasks that depend on it are complete
default:
deps:
- with-docker-service
cmds:
- echo "Doing stuff"
defer is pretty close to what I want, but it only waits for the next commands, not the dependents tasks. I guess we need a new keyword (Or modifying the semantics of defer, which sounds more problematic)
The text was updated successfully, but these errors were encountered:
Currently defer is using the go defer keyword and as such is limited to the executing scope of a/the task. I did an experiment where I added "defer functions" to the Run context, and then called those "defer functions" after the task had completed. It worked ... not sure how flaky it as a mechanism though.
$ ~/go/bin/task bar -v
task: "bar" started
task: "docker" started
task: [docker] echo "START"
START
task: "docker" finished
task: [bar] echo "bar"
bar
task: "bar" finished
task: [docker] echo "STOP"
STOP
The code is like this, in case any one wants to take the idea further.
func (e *Executor) Run(ctx context.Context, calls ...*ast.Call) error {
...
var deferedTasks []func()
ctx = context.WithValue(ctx, "deferedTasks", &deferedTasks)
...
for _, f := range deferedTasks {
f()
}
...
}
...
for i := range t.Cmds {
if t.Cmds[i].Defer {
if x, ok := ctx.Value("deferedTasks").(*[]func()); ok {
deferIdx := i // force immediate evaluation of parameter "i"
*x = append(*x, func() {
e.runDeferred(t, call, deferIdx)
})
} else {
e.Logger.VerboseErrf(logger.Yellow, "task: defer not possible: %d\n", i)
}
continue
}
I think it might be better to put the defer/final functions on the executor struct ... still, you get the idea.
Hello, and thanks for this great tool!
I was writing a task today and wished for a better way to express it:
docker-compose up ...
)docker-compose down ...
)(For context, the service in question takes a lot of RAM, so I do want to stop it when done)
What I have right now is something like this:
This works well enough, but the "docker-service" would be better expressed as a dependency. It should also be possible to have multiple concurrent tasks that depend on this.
I think it would be great if we could do something like this:
defer
is pretty close to what I want, but it only waits for the next commands, not the dependents tasks. I guess we need a new keyword (Or modifying the semantics of defer, which sounds more problematic)The text was updated successfully, but these errors were encountered: