Make the scouting background scraper more generic
We're already using the code for more than just scraping The Blue
Alliance. I'd like to expand it to even more use cases. This patch
moves the code into a more appropriate directory and changes the
module name correspondingly.
Signed-off-by: Philipp Schrader <philipp.schrader@gmail.com>
Change-Id: Ic0288231f9c0d12f682eb75ac265f090d1ce9165
diff --git a/scouting/background_task/BUILD b/scouting/background_task/BUILD
new file mode 100644
index 0000000..20726ca
--- /dev/null
+++ b/scouting/background_task/BUILD
@@ -0,0 +1,9 @@
+load("@io_bazel_rules_go//go:def.bzl", "go_library")
+
+go_library(
+ name = "background_task",
+ srcs = ["background_task.go"],
+ importpath = "github.com/frc971/971-Robot-Code/scouting/background_task",
+ target_compatible_with = ["@platforms//cpu:x86_64"],
+ visibility = ["//visibility:public"],
+)
diff --git a/scouting/scraping/background/background.go b/scouting/background_task/background_task.go
similarity index 85%
rename from scouting/scraping/background/background.go
rename to scouting/background_task/background_task.go
index 5af8c3e..2d0c4a5 100644
--- a/scouting/scraping/background/background.go
+++ b/scouting/background_task/background_task.go
@@ -1,4 +1,4 @@
-package background
+package background_task
import (
"time"
@@ -7,12 +7,12 @@
// A helper to run a function in the background every ~10 minutes. Technically
// can be used for a lot of different things, but is primarily geared towards
// scraping thebluealliance.com.
-type BackgroundScraper struct {
+type BackgroundTask struct {
doneChan chan<- bool
checkStopped chan<- bool
}
-func (scraper *BackgroundScraper) Start(scrape func()) {
+func (scraper *BackgroundTask) Start(scrape func()) {
scraper.doneChan = make(chan bool, 1)
scraper.checkStopped = make(chan bool, 1)
@@ -39,7 +39,7 @@
}()
}
-func (scraper *BackgroundScraper) Stop() {
+func (scraper *BackgroundTask) Stop() {
scraper.doneChan <- true
for {
diff --git a/scouting/scraping/background/BUILD b/scouting/scraping/background/BUILD
deleted file mode 100644
index 9aa92c9..0000000
--- a/scouting/scraping/background/BUILD
+++ /dev/null
@@ -1,9 +0,0 @@
-load("@io_bazel_rules_go//go:def.bzl", "go_library")
-
-go_library(
- name = "background",
- srcs = ["background.go"],
- importpath = "github.com/frc971/971-Robot-Code/scouting/scraping/background",
- target_compatible_with = ["@platforms//cpu:x86_64"],
- visibility = ["//visibility:public"],
-)
diff --git a/scouting/webserver/BUILD b/scouting/webserver/BUILD
index 934b50a..f5b0a81 100644
--- a/scouting/webserver/BUILD
+++ b/scouting/webserver/BUILD
@@ -7,8 +7,8 @@
target_compatible_with = ["@platforms//cpu:x86_64"],
visibility = ["//visibility:private"],
deps = [
+ "//scouting/background_task",
"//scouting/db",
- "//scouting/scraping/background",
"//scouting/webserver/driver_ranking",
"//scouting/webserver/match_list",
"//scouting/webserver/rankings",
diff --git a/scouting/webserver/main.go b/scouting/webserver/main.go
index 1b5a002..ba9d120 100644
--- a/scouting/webserver/main.go
+++ b/scouting/webserver/main.go
@@ -14,8 +14,8 @@
"syscall"
"time"
+ "github.com/frc971/971-Robot-Code/scouting/background_task"
"github.com/frc971/971-Robot-Code/scouting/db"
- "github.com/frc971/971-Robot-Code/scouting/scraping/background"
"github.com/frc971/971-Robot-Code/scouting/webserver/driver_ranking"
"github.com/frc971/971-Robot-Code/scouting/webserver/match_list"
"github.com/frc971/971-Robot-Code/scouting/webserver/rankings"
@@ -141,17 +141,17 @@
// Since Go doesn't support default arguments, we use 0 and "" to
// indicate that we want to source the values from the config.
- matchListScraper := background.BackgroundScraper{}
+ matchListScraper := background_task.BackgroundTask{}
matchListScraper.Start(func() {
match_list.GetMatchList(database, 0, "", *blueAllianceConfigPtr)
})
- rankingsScraper := background.BackgroundScraper{}
+ rankingsScraper := background_task.BackgroundTask{}
rankingsScraper.Start(func() {
rankings.GetRankings(database, 0, "", *blueAllianceConfigPtr)
})
- driverRankingParser := background.BackgroundScraper{}
+ driverRankingParser := background_task.BackgroundTask{}
driverRankingParser.Start(func() {
// Specify "" as the script path here so that the default is
// used.
diff --git a/scouting/webserver/rankings/BUILD b/scouting/webserver/rankings/BUILD
index 4696d26..5192e87 100644
--- a/scouting/webserver/rankings/BUILD
+++ b/scouting/webserver/rankings/BUILD
@@ -20,8 +20,8 @@
],
embed = [":rankings"],
deps = [
+ "//scouting/background_task",
"//scouting/db",
- "//scouting/scraping/background",
"//scouting/webserver/server",
],
)
diff --git a/scouting/webserver/rankings/rankings_test.go b/scouting/webserver/rankings/rankings_test.go
index 6f8af3b..03a4ac6 100644
--- a/scouting/webserver/rankings/rankings_test.go
+++ b/scouting/webserver/rankings/rankings_test.go
@@ -1,14 +1,15 @@
package rankings
import (
- "github.com/frc971/971-Robot-Code/scouting/db"
- "github.com/frc971/971-Robot-Code/scouting/scraping/background"
- "github.com/frc971/971-Robot-Code/scouting/webserver/server"
"net/http"
"reflect"
"strings"
"testing"
"time"
+
+ "github.com/frc971/971-Robot-Code/scouting/background_task"
+ "github.com/frc971/971-Robot-Code/scouting/db"
+ "github.com/frc971/971-Robot-Code/scouting/webserver/server"
)
type MockDatabase struct {
@@ -37,7 +38,7 @@
func TestGetRankings(t *testing.T) {
database := MockDatabase{}
- scraper := background.BackgroundScraper{}
+ scraper := background_task.BackgroundTask{}
tbaServer := server.NewScoutingServer()
tbaServer.Handle("/", ServeRankings(t, http.FileServer(http.Dir("../../"))))
tbaServer.Start(8000)