riverqueue / river

Fast and reliable background jobs in Go
https://riverqueue.com
Mozilla Public License 2.0
3.51k stars 94 forks source link

Add `startstop.StartAll` helper to start a series of services #517

Closed brandur closed 2 months ago

brandur commented 2 months ago

Add a StartAll helper that starts a number of services at once, also taking care that in the event of a problem, any services that had started are once stopped. I found the use of something like this convenient while trying some service code in River UI.

I also make a couple tweaks so that the Stopped channel becomes a little safer to use. Like Started, it will preallocate itself if called before a service is started. It's still not safe to call while stopping or after a stop, but its ergonomics still measurably improve.

Lastly, I pull a somewhat unrelated change to add a NewArchetype function in for easily creating an archetype in non-test environments. Also found this useful when bringing use of archetypes into River UI.

brandur commented 2 months ago

Hm, I think this one may have snowballed too much.

brandur commented 2 months ago

@bgentry Okay I ended up reverting the behavior changes that I mentioned in comments above. I still did have to tweak how Stopped work in BaseStartStop so I could accurately test the new StartAll, but I put in an escape hatch so that river.Client's Stopped could behave identically to how it did before. Mind taking a look?

brandur commented 2 months ago

Thx.