summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
authorBen Busby <contact@benbusby.com>2025-02-25 17:21:05 -0700
committerBen Busby <contact@benbusby.com>2025-02-25 17:21:05 -0700
commitd15e05d39ea7fec7f8f975e8aebaf7e8c9ce5b94 (patch)
tree3ad5f6c6551ce00adfc562fd86a8991266516ff1 /db
parent99e5dfcac221b7ef1653144b23b6b6455ce452a5 (diff)
downloadfarside-d15e05d39ea7fec7f8f975e8aebaf7e8c9ce5b94.tar.gz
Allow skipping instance checks for particular services
Services like searxng don't need to have instance checks performed since the nightly cron task filters out the instances already.
Diffstat (limited to 'db')
-rw-r--r--db/cron.go17
1 files changed, 15 insertions, 2 deletions
diff --git a/db/cron.go b/db/cron.go
index 7b7e9ce..4f0f2dc 100644
--- a/db/cron.go
+++ b/db/cron.go
@@ -7,6 +7,7 @@ import (
"log"
"net/http"
"os"
+ "slices"
"strings"
"time"
@@ -18,9 +19,14 @@ const defaultPrimary = "https://farside.link/state"
const defaultCFPrimary = "https://cf.farside.link/state"
var LastUpdate time.Time
+var skipInstanceChecks = []string{
+ "searx",
+ "searxng",
+}
func InitCronTasks() {
log.Println("Initializing cron tasks...")
+ updateServiceList()
cronDisabled := os.Getenv("FARSIDE_CRON")
if len(cronDisabled) == 0 || cronDisabled == "1" {
@@ -58,6 +64,8 @@ func queryServiceInstances() {
}
for _, service := range services.ServiceList {
+ canSkip := slices.Contains[[]string, string](skipInstanceChecks, service.Type)
+
fmt.Printf("===== %s =====\n", service.Type)
var instances []string
for _, instance := range service.Instances {
@@ -68,7 +76,7 @@ func queryServiceInstances() {
available := queryServiceInstance(
instance,
testURL,
- )
+ canSkip)
if available {
instances = append(instances, instance)
@@ -105,12 +113,17 @@ func fetchInstancesFromPrimary() ([]services.Service, error) {
return serviceList, err
}
-func queryServiceInstance(instance, testURL string) bool {
+func queryServiceInstance(instance, testURL string, canSkipCheck bool) bool {
testMode := os.Getenv("FARSIDE_TEST")
if len(testMode) > 0 && testMode == "1" {
return true
}
+ if canSkipCheck {
+ fmt.Printf(" [INFO] Adding %s\n", instance)
+ return true
+ }
+
ua := "Mozilla/5.0 (compatible; Farside/1.0.0; +https://farside.link)"
url := instance + testURL