mage icon indicating copy to clipboard operation
mage copied to clipboard

Add support for running tasks on shutdown

Open a-palchikov opened this issue 4 years ago • 6 comments

This PR adds support for arbitrary tasks to run on shutdown. It is useful when the builder needs to clean up on exit.

I opted to implement it as a special variable with the name Deinit which follows the precedent of Default - let me know if there's a better or more idiomatic way to introduce this inside the template.

a-palchikov avatar May 06 '21 14:05 a-palchikov

Hey! Any chance for this getting some traction again? We're using Magefile at @seatgeek and we could really use this to do proper cleanup of more complex tasks (like docker compose) on exit rather than task specific exit

cc @natefinch

jippi avatar Apr 20 '22 09:04 jippi

Yeah, I think it makes sense. Maybe implemented like testing.Tcs Cleanup, so you can treat it like defer, but for the whole process run.

natefinch avatar Apr 20 '22 17:04 natefinch

Yeah, so, I think it would be better to make a mg.Cleanup() method that stores a list of functions to call that are called in a defer in the generated main functions.

The deinit is fine, but it means that deinit doesn't know what code has run. It would be better to have a place where you can shove code as you need it, just like defer.

natefinch avatar Apr 21 '22 03:04 natefinch

I like mg.Cleanup a lot better to be honest! :)

jippi avatar Apr 21 '22 08:04 jippi

Agree on mg.Cleanup - I can take a stab at it in this PR.

a-palchikov avatar Apr 21 '22 12:04 a-palchikov

Sounds fantastic @a-palchikov - thank you! :)

jippi avatar Apr 21 '22 12:04 jippi