Skip to content

internal: Add additional goroutine utilities

Warren Gifford requested to merge ef/goroutine-pkg into main

Created by: efritz

This PR adds additional utilities to the internal/goroutine package which will be used to standardize the startup of precise code intel (and possibly other) services which are a composition of lots of many goroutines. A recent issue has uncovered that the shutting down of these services has not been implemented correctly. These services are similar enough that they should share the same tested base abstraction.

New utilities include:

A periodic goroutine

This takes a handler (with optional error handling and finalizer extensions) and an interval and calls the handler in a background goroutine, waiting the interval between invocations. This can be used to replace the timing/clock/context checking code that is used in the precise code intel resetters, janitors, and index/indexability schedulers.

See https://github.com/sourcegraph/sourcegraph/pull/13263 for example usage.

A background task monitoring function

This takes a set of background routine values (something with a Start and Stop function). This will call each routine's Start function in its own background routine, then wait for a SIGINT or SIGHUP before calling shutdown. This function blocks until all routines (start and stop methods) have returned. This will replace a good portion of the main function from each of the precise code intel services, and also fixes a portion of a bug linked above (in which Stop is not called in the correct order for background routines and one blocks on another).

See https://github.com/sourcegraph/sourcegraph/pull/13264 for example usage.

Merge request reports

Loading