nur icon indicating copy to clipboard operation
nur copied to clipboard

Long-lived tasks

Open saona-raimundo opened this issue 5 months ago • 0 comments

Is your feature request related to a problem? Please describe. I would like to run a tasks that starts an http server, do more things after that, and allows to control when to kill the http server.

In nu, Background Jobs are used for this. Currently, there is no way to dispatch a job so it continues after the script finishes. Moreover, to kill a job, you need its id, which you can check with job list.

My first approach was to define the following nurfile

# nurfile
def "nur open" [] {
	job spawn { http-server -p 8080 }
        job spawn { start http://localhost:8080/ }
}

I use job spawn in the first line because this is a long-lived command, and would like to open the browser automatically after staring the http server. Here, running nur open has no effect.

My second approach is

# nurfile
def "nur open" [] {
	job spawn { http-server -p 8080 }
        start http://localhost:8080/
}

Running nur open has (almost) the desired effect: the server runs, the browser opens. The issue is that the http server keeps running forever (and I do not know how to close it except stopping the process).

Describe the solution you'd like I am not sure, but... On the second approach, even if I printed the id of a job spawn, I would not know where to run job kill <ID>. If I understand correctly, there is some nu session that starts when running nur open. In this case, to kill the job started, I imagine the solution would be to be able to run job kill <ID> in that nu session, even after the command nur open finished!

Describe alternatives you've considered This is not an alternative, but I do not fully understand why the first approach fails.

Additional context None

saona-raimundo avatar Nov 22 '25 21:11 saona-raimundo