Skip to content

Idea: Add a global defer: attribute to cleanup stuff before exiting task? #2273

@andreynering

Description

@andreynering

Keep in mind that the original request asks for running a cleanup before exiting Task, and not after every task ran.

Not sure if defer: if the right keywork for this. cleanup: could be clearer on the intention, but defer: is more consistent to what we already have.


Discussed in #2272

Originally posted by @ssbarnea May 28, 2025

How can I make task run some commands always before exiting regardless which task was called?

I want to add some special cleanup logic at the end of execution of task command but one that would run regardless which task I called.

For maintenance reasons I cannot really add an extra defer task of each task being added, so I need to rely of a feature that would allow me to define this special type of implicit "task", one that would be called only before exiting.

It would be key that this task is not called before task executable exits, as we don't want to be called accidentally in the middle of task executions.

I am aware that that there is a small risk of this being called if someone is calling task recursively using shell commands, but that is a small price to pay (in theory nesting can be detected via env vars).

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: execChanges related to the execution of commands.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions