-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Consolidate on one set state query + adapter/completer function [boil…
…erplate reduction] (#101) This one's a clean up aimed at doing a massive boilerplate reduction in our sqlc queries, the adapter, and the completer(s). We have a few current problems: * Every "set state" query like `JobCompleteIfRunning`, `JobErrorIfRunning`, etc. are all separate sqlc queries, and worse yet, all very long ones that are all practically identical with very minor but important differences that are hard to spot without examining them character by character. * Every one of these queries get exposed through the adapter as a separate function that's implemented in the interface, `StandardAdapter`, and the mock `TestAdapter`, requiring lots of LOC. * They're all exposed yet again in the `Completer` interface, along with both implementations of `Completer`. Which again, is a lot of LOC. Here, we show that with some fairly minor tweaks, we can consolidate all of this state updating into a single query that's no longer than any one of the originals, and then simplify both the adapter and completer to model access to it as a general `JobSetState` function with a number of params constructors that function to produce the necessary parameters for each type of state of update (complete, error, snooze, etc.). Total LOCs are reduced by *a lot*. `river_job.sql` just by itself has 40% fewer lines, and with many more removed in the adapters and completers. This has the effect of a lot less noise, but also makes refactoring easier because there's less that has to change. Furthermore, I don't believe there's any significant reduction in API ergonomics or safety. It's still not perfect -- there's still way too much scaffolding in the completers in particular for example, but more improvements to come.
- Loading branch information
Showing
12 changed files
with
253 additions
and
932 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.