refactor(database): move worker logic into separate package
Based off of https://github.com/go-vela/server/pull/574, https://github.com/go-vela/server/pull/663 and https://github.com/go-vela/server/pull/687
This change continues the refactor efforts initially introduced in the above PRs.
This adds a new worker package to the github.com/go-vela/server/database package.
This contains a WorkerService interface declaring all functions necessary for worker based interactions with the database:
https://github.com/go-vela/server/blob/7991f03903622a820698678037cbe482828d72a2/database/worker/service.go#L11-L43
This package also contains the engine which implements the above service interface:
https://github.com/go-vela/server/blob/7991f03903622a820698678037cbe482828d72a2/database/worker/worker.go#L23-L37
This engine contains no raw SQL queries for integrating with the workers table.
Instead, we leverage our DB library's (https://gorm.io/) agnostic abstraction for integrating with that table.
Codecov Report
Merging #692 (729481d) into main (4335e56) will decrease coverage by
0.14%. The diff coverage is77.46%.
@@ Coverage Diff @@
## main #692 +/- ##
==========================================
- Coverage 54.94% 54.79% -0.15%
==========================================
Files 211 216 +5
Lines 16030 16015 -15
==========================================
- Hits 8808 8776 -32
- Misses 6845 6857 +12
- Partials 377 382 +5
| Impacted Files | Coverage Δ | |
|---|---|---|
| api/build.go | 1.64% <0.00%> (ø) |
|
| api/metrics.go | 0.00% <0.00%> (ø) |
|
| api/worker.go | 0.00% <0.00%> (ø) |
|
| router/middleware/executors/executors.go | 3.70% <0.00%> (ø) |
|
| database/worker/worker.go | 51.72% <51.72%> (ø) |
|
| database/worker/list.go | 72.72% <60.86%> (ø) |
|
| database/sqlite/sqlite.go | 63.44% <62.50%> (+1.26%) |
:arrow_up: |
| database/postgres/postgres.go | 63.56% <70.00%> (+1.52%) |
:arrow_up: |
| database/worker/get.go | 81.25% <81.25%> (ø) |
|
| database/worker/get_hostname.go | 83.33% <83.33%> (ø) |
|
| ... and 9 more |
@cognifloyd GetWorkerByAddress was not used anywhere in the codebase 😅
When I discovered this during the refactor, I elected to not include it.
However, if we feel there is a good reason to keep it, I could certainly do so.