diff options
| author | Ben Busby <contact@benbusby.com> | 2023-07-11 12:30:13 -0600 |
|---|---|---|
| committer | Ben Busby <contact@benbusby.com> | 2023-07-11 12:34:31 -0600 |
| commit | c0706bfe9b354abfadaa2d38f698d3309db3428b (patch) | |
| tree | df53c76c4898bda21f7e51e5a3db7ae97fd335d1 /lib | |
| parent | dcc4a9f4b1fb2eca5239990a8011a5af27f1593c (diff) | |
| download | farside-c0706bfe9b354abfadaa2d38f698d3309db3428b.tar.gz | |
Allow separation of instance and API URLs
Instance URLs and API URLs are not always the same, and require
different testing strategies. This allows the two types of URLs for an
instance, as well as the testing path, to be separated by a "|" character.
When Farside runs the instance checker, it will split instance strings
by that character and perform separate tests. Instances without a
separate API URL will only be tested once against their primary instance
URL.
Currently the only service using this paradigm is Piped, but allows for
others using the same approach to be added/tested in Farside in the
future.
Closes #115
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/farside/instances.ex | 54 |
1 files changed, 43 insertions, 11 deletions
diff --git a/lib/farside/instances.ex b/lib/farside/instances.ex index 279d48a..d02a082 100644 --- a/lib/farside/instances.ex +++ b/lib/farside/instances.ex @@ -20,6 +20,8 @@ defmodule Farside.Instances do end def request(url) do + IO.puts("#{@debug_spacer}#{url}") + cond do System.get_env("FARSIDE_TEST") -> :good @@ -57,19 +59,26 @@ defmodule Farside.Instances do result = cond do Enum.member?(@skip_service_updates, service.type) -> - service.instances + get_service_vals(service.instances) true -> Enum.filter(service.instances, fn instance_url -> - request_url = - instance_url <> - EEx.eval_string( - service.test_url, - query: Enum.random(@queries) - ) - - IO.puts("#{@debug_spacer}#{request_url}") - - request(request_url) == :good + test_url = get_test_val(instance_url) + test_path = get_test_val(service.test_url) + test_request_url = gen_validation_url(test_url, test_path) + + service_url = get_service_val(instance_url) + service_path = get_service_val(service.test_url) + service_request_url = gen_validation_url(service_url, service_path) + + cond do + service_url != test_url -> + service_up = request(service_request_url) + test_up = request(test_request_url) + + service_up == :good && test_up == :good + true -> + request(test_request_url) == :good + end end) end @@ -79,6 +88,9 @@ defmodule Farside.Instances do end def add_to_db(service, instances) do + # Ensure only service URLs are inserted, not test URLs (separated by "|") + instances = get_service_vals(instances) + # Remove previous list of instances CubDB.delete(CubDB, "#{@service_prefix}#{service.type}") @@ -99,4 +111,24 @@ defmodule Farside.Instances do IO.write(file, "#{service_name}: #{inspect(results)}\n") File.close(file) end + + def gen_validation_url(url, path) do + url <> EEx.eval_string(path, query: Enum.random(@queries)) + end + + def get_service_vals(services) do + Enum.map(services, fn x -> get_service_val(x) end) + end + + def get_service_val(service) do + String.split(service, "|") |> List.first + end + + def get_test_vals(services) do + Enum.map(services, fn x -> get_test_val(x) end) + end + + def get_test_val(service) do + String.split(service, "|") |> List.last + end end |
