Made the fetcher a Fetcher type with per-source config, and ran it in job-search serve
fetcher.Run(ctx, conf, since) becomes New(&conf.Sources, opts...) and Run(ctx, since). Each worker now takes only its own source's config, and Run starts each one through a closure that binds it. Cancelling ctx stops the workers through the Fetcher's background context, and Run always waits for every worker before returning their joined errors. The findatender client no longer holds the configuration: New takes only the API root, ReloadConfig is gone, and request tracing follows logging.IsDebugEnabled(). The FindAOpportunity worker is now FindATender. job-search serve runs the fetcher alongside the HTTP server. A source that fails stops the server, and the server stopping stops the sources; with no sources enabled the server keeps running. fetcher service and fetcher fts-once use the new APIs.
This commit is contained in:
1 parent
f0c171c8a8
commit
18db462d89
12 files changed
+269
-214
No files matched your search
@@ -14,12 +14,11 @@ import (
|
||||
)
|
||||
|
||||
func TestNew(t *testing.T) {
|
||||
conf := testConfig("warn")
|
||||
ft := New(conf, "https://example/api")
|
||||
ft := New("https://example/api")
|
||||
defer ft.Shutdown()
|
||||
|
||||
if ft.config != conf || ft.apiRoot != "https://example/api" {
|
||||
t.Errorf("New did not keep its arguments: %+v", ft)
|
||||
if ft.apiRoot != "https://example/api" {
|
||||
t.Errorf("New did not keep its API root: %+v", ft)
|
||||
}
|
||||
if ft.httpClient == nil {
|
||||
t.Fatal("no http client")
|
||||
@@ -37,18 +36,8 @@ func TestNew(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestReloadConfig(t *testing.T) {
|
||||
ft := New(testConfig("warn"), "")
|
||||
defer ft.Shutdown()
|
||||
conf := testConfig("debug")
|
||||
ft.ReloadConfig(conf)
|
||||
if ft.config != conf {
|
||||
t.Error("config not replaced")
|
||||
}
|
||||
}
|
||||
|
||||
func TestWith(t *testing.T) {
|
||||
ft := New(testConfig("warn"), "")
|
||||
ft := New("")
|
||||
defer ft.Shutdown()
|
||||
|
||||
// Passing nil on purpose to test that case.
|
||||
@@ -69,8 +58,8 @@ func TestWith(t *testing.T) {
|
||||
if ft.ctx != nil {
|
||||
t.Error("With changed the original")
|
||||
}
|
||||
if got.httpClient != ft.httpClient || got.config != ft.config {
|
||||
t.Error("copy should share the client and config")
|
||||
if got.httpClient != ft.httpClient {
|
||||
t.Error("copy should share the client")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,7 +117,7 @@ func TestFetchAllPublic(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
ft, _ = newTestFT(t, "warn", func(w http.ResponseWriter, r *http.Request) {
|
||||
ft, _ = newTestFT(t, false, func(w http.ResponseWriter, r *http.Request) {
|
||||
io.WriteString(w, "not json")
|
||||
})
|
||||
if _, err := ft.FetchAll(time.Now(), false); err == nil {
|
||||
|
||||
Reference in new issue
Block a user