Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run cleanup_task on SIGINT #877

Open
SomaticIT opened this issue Jun 22, 2023 · 3 comments
Open

Run cleanup_task on SIGINT #877

SomaticIT opened this issue Jun 22, 2023 · 3 comments

Comments

@SomaticIT
Copy link

Describe The Bug

The cleanup_task does not run when flow is interrupted by Ctrl+C.

This is problematic when using cargo watch (or similar).

Exemple:
Imagine we are developing a web server with actix-web. We need a redis database to store some data.
We want to setup the environment before runing cargo watch and clean up the environment when we interupt the watch.

To Reproduce

1/ Setup Makefile.toml

[tasks.dev]
run_task = { name = ["setup ", "dev-watch"], fork = true, cleanup_task = "cleanup" }

[tasks.dev-watch]
command = "cargo"
args = ["watch", "-x", "run"]

[tasks.setup]
script = "echo setup env"

[tasks.cleanup]
script = "echo cleanup env"

2/ Run cargo make dev
3/ Ctrl+C

The task cleanup is never executed.

Error Stack

None.

@sagiegurari
Copy link
Owner

@SomaticIT sorry for late reply.
i totally get your use case, but i feel its not something standard for scripts to do. usually the signal would kill the process.
maybe you need to cleanup any previous leftovers before the execution?

@SomaticIT
Copy link
Author

@sagiegurari, thank you for your reply.

I understand your mean.

However, it's not uncommon to see scripts that react to the SIGINT signal to clean their ressources.

  • eg: telepresence clean remote ressources on k8s and close the connection
  • eg2: actix-web clean all workers to avoid zombies

To clarify a good use case for this feature, it would be useful to start some containers before running the dev server and stopping/cleaning these containers when killing the server.

Maybe to avoid ambiguities, we could add an option (eg : cleanup_on_sigint: true or on_sigint: "task_name").
What do you think?

@sagiegurari
Copy link
Owner

there is some unstable feature for singal handling which kills child process and might be a good start for reusing for this issue.
would you like to investigate a solution with my help and publish a PR? or prefer for me to look at it?
heads up, it won't be trivial.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants