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

Async cm_run_task #493

Closed
AntonOellerer opened this issue Nov 23, 2020 · 8 comments
Closed

Async cm_run_task #493

AntonOellerer opened this issue Nov 23, 2020 · 8 comments
Assignees
Milestone

Comments

@AntonOellerer
Copy link

Hey,
Thank you a lot for this great tool!
One thing I came across when using cargo-make together with duckscript to run system tests is the problem of starting processes we need for successful execution of another task which we run later in the script.
The cm_run_task command is really nice, but as far as I can tell there is no way to run it in the background, so that we can move on to other tasks.
I opened an issue for a related feature for duckscript here.

Feature Description

An option for cm_run_task so that it is started in a subprocess and execution of the main script continues.

Describe The Solution You'd Like

A flag for the cm_run_task command so that the task is executed in the background.

Code Sample

pid = cm_run_task --silent start-server
@sagiegurari
Copy link
Owner

thanks for the idea. i'll take a look at starting it in a background thread and not waiting for it.
just need to make sure it doesn't block the main process from exiting.
i guess i won't call the flag silent, maybe background/spawn/something like that.

@sagiegurari
Copy link
Owner

@AntonOellerer I implemented the changes in duckscript and published them.
As for this one, i implemented it in a dev branch 0.32.10 and you can install cargo make from that branch and test it.
basically you need to add --async before the task name and it will be invoked on a separate thread.
however:

  • unlike your request in duckscript spawn - this one will not be silent. duckscript spawn starts a new sub processes so i just redirect its output to null, but here, i start a new thread.
  • the global flow will not wait for this thread to finish (i think thats actually good for you), which means it will just kill the process at the end.

if you can just test it out and tell me if it works well for you?
this dev branch also has the new duckscript runtime+sdk so you can test the other spawn changes you requested.

@AntonOellerer
Copy link
Author

Thank you a lot, I will take a look at it tomorrow!

@AntonOellerer
Copy link
Author

Hey, when testing the --async flag, there seems to be a problem with the cwd command.
The duckscript is

cm_run_task --async start-server
echo Running tests
cm_run_task test-server

and start-server looks like this:

[tasks.start-server]
description = "start the server"
category = "start"
command = "cargo"
args = ["run"]
cwd = "server"
watch = { ignore_pattern = "client/*" }
env = { ROCKET_ADDRESS = "127.0.0.1" }

When running makers test-system, I get the following log:

[cargo-make] INFO - makers 0.32.9
[cargo-make] INFO - Build File: Makefile.toml
[cargo-make] INFO - Task: test-system
[cargo-make] INFO - Profile: development
[cargo-make] INFO - Running Task: test-system
Running tests 
[cargo-make] ERROR - Unable to set current working directory to: tests Os {
    code: 2,
    kind: NotFound,
    message: "No such file or directory",
}
[cargo-make] WARN - Build Failed.

@sagiegurari
Copy link
Owner

thanks for the feedback.
i actually documented it that when running tasks in parallel, things like env vars anf cwd may be an issue.
this is because cargo make updates the cwd per task needs and reverts once done.
if you are doing it in async that can result in big issues and is not recommended.
instead, i suggest the command itself should handle it, either by updating the path to the executable or switching from command to script and doing cd server && command

@AntonOellerer
Copy link
Author

The two duck related changes (sagiegurari/duckscript#142 and sagiegurari/duckscript#144) work, thank you!

@AntonOellerer
Copy link
Author

Yeah, I am doing it in the script now, thank you!

@AntonOellerer
Copy link
Author

I tested cm_run_task --async now with commands not changing the working directory and it worked flawlessly, thank you again!

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