1
0
Fork 0
mirror of https://github.com/benbusby/farside.git synced 2025-04-25 13:10:02 +00:00

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.
This commit is contained in:
Ben Busby 2025-02-25 17:21:05 -07:00
parent 99e5dfcac2
commit d15e05d39e
No known key found for this signature in database
GPG key ID: B9B7231E01D924A1
2 changed files with 15 additions and 3 deletions

View file

@ -7,6 +7,7 @@ import (
"log" "log"
"net/http" "net/http"
"os" "os"
"slices"
"strings" "strings"
"time" "time"
@ -18,9 +19,14 @@ const defaultPrimary = "https://farside.link/state"
const defaultCFPrimary = "https://cf.farside.link/state" const defaultCFPrimary = "https://cf.farside.link/state"
var LastUpdate time.Time var LastUpdate time.Time
var skipInstanceChecks = []string{
"searx",
"searxng",
}
func InitCronTasks() { func InitCronTasks() {
log.Println("Initializing cron tasks...") log.Println("Initializing cron tasks...")
updateServiceList()
cronDisabled := os.Getenv("FARSIDE_CRON") cronDisabled := os.Getenv("FARSIDE_CRON")
if len(cronDisabled) == 0 || cronDisabled == "1" { if len(cronDisabled) == 0 || cronDisabled == "1" {
@ -58,6 +64,8 @@ func queryServiceInstances() {
} }
for _, service := range services.ServiceList { for _, service := range services.ServiceList {
canSkip := slices.Contains[[]string, string](skipInstanceChecks, service.Type)
fmt.Printf("===== %s =====\n", service.Type) fmt.Printf("===== %s =====\n", service.Type)
var instances []string var instances []string
for _, instance := range service.Instances { for _, instance := range service.Instances {
@ -68,7 +76,7 @@ func queryServiceInstances() {
available := queryServiceInstance( available := queryServiceInstance(
instance, instance,
testURL, testURL,
) canSkip)
if available { if available {
instances = append(instances, instance) instances = append(instances, instance)
@ -105,12 +113,17 @@ func fetchInstancesFromPrimary() ([]services.Service, error) {
return serviceList, err return serviceList, err
} }
func queryServiceInstance(instance, testURL string) bool { func queryServiceInstance(instance, testURL string, canSkipCheck bool) bool {
testMode := os.Getenv("FARSIDE_TEST") testMode := os.Getenv("FARSIDE_TEST")
if len(testMode) > 0 && testMode == "1" { if len(testMode) > 0 && testMode == "1" {
return true 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)" ua := "Mozilla/5.0 (compatible; Farside/1.0.0; +https://farside.link)"
url := instance + testURL url := instance + testURL

View file

@ -47,7 +47,6 @@ func GetServicesFileName() string {
return serviceJSON return serviceJSON
} }
func FetchServicesFile(serviceJSON string) ([]byte, error) { func FetchServicesFile(serviceJSON string) ([]byte, error) {
resp, err := http.Get(baseRepoLink + serviceJSON) resp, err := http.Get(baseRepoLink + serviceJSON)
if err != nil { if err != nil {