nix-community / lorri

Your project’s nix-env [maintainer=@Profpatsch,@nyarly]
Apache License 2.0
663 stars 24 forks source link

Fix build loop #7

Closed Profpatsch closed 3 years ago

Profpatsch commented 3 years ago

fix(build_loop): always schedule at most one other build 80e8eb1

This switches the build loop from blockingly running a build for every event that ever appeared, to always at most running one additional build as soon as the current one finishes.

Whenver we start a new build, we take the current state of the environment to run nix, which means that all events that happen while a build is running (e.g. pings, filesystem events &c.) should be collapsed into one (1) extra build to be scheduled right after the current build finishes.

So there is now a stateful current_build variable, which contains one BuildState that is mutably updated from NotRunning to Running and if it’s already running to RunningAndScheduled. Then the “build finished” event becomes just another handler in our giant select!, meaning that as soon as a build finishes we can either go back to NotRunning or go to Running if there had been another build scheduled.

For now this means inlining once_with_send into the build loop, further refactors to follow to make the logic easier to understand.

Checklist

Profpatsch commented 3 years ago

@symphorien, can you try this out, I think this supersedes https://github.com/nix-community/lorri/pull/3 in a more principled way, while also simplifying the whole thing considerably.

symphorien commented 3 years ago

~I can still reproduce https://github.com/target/lorri/issues/464 on top of this PR.~

symphorien commented 3 years ago

Ah no sorry, I had my timing off, it works.

Profpatsch commented 3 years ago

Okay, added the change log, will merge and then we can release a new version upstream.

symphorien commented 3 years ago

It looks like this builds the project on every ping.

sternenseemann commented 3 years ago

It looks like this builds the project on every ping.

I didn't encounter that behavior.

symphorien commented 3 years ago

See https://github.com/nix-community/lorri/issues/11 for reproducer.