tools: distribute vpm queries randomly between the available backend servers

master
Delyan Angelov 2022-06-21 12:58:22 +03:00
parent cab6355a38
commit c6f94e9cab
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
1 changed files with 5 additions and 2 deletions

View File

@ -4,6 +4,7 @@
module main module main
import os import os
import rand
import os.cmdline import os.cmdline
import net.http import net.http
import net.urllib import net.urllib
@ -13,6 +14,7 @@ import v.vmod
const ( const (
default_vpm_server_urls = ['https://vpm.vlang.io', 'https://vpm.url4e.com'] default_vpm_server_urls = ['https://vpm.vlang.io', 'https://vpm.url4e.com']
vpm_server_urls = rand.shuffle_clone(default_vpm_server_urls) or { [] } // ensure that all queries are distributed fairly
valid_vpm_commands = ['help', 'search', 'install', 'update', 'upgrade', 'outdated', valid_vpm_commands = ['help', 'search', 'install', 'update', 'upgrade', 'outdated',
'list', 'remove', 'show'] 'list', 'remove', 'show']
excluded_dirs = ['cache', 'vlib'] excluded_dirs = ['cache', 'vlib']
@ -664,7 +666,7 @@ fn get_working_server_url() string {
server_urls := if settings.server_urls.len > 0 { server_urls := if settings.server_urls.len > 0 {
settings.server_urls settings.server_urls
} else { } else {
default_vpm_server_urls vpm_server_urls
} }
for url in server_urls { for url in server_urls {
verbose_println('Trying server url: $url') verbose_println('Trying server url: $url')
@ -725,7 +727,8 @@ fn get_module_meta_info(name string) ?Mod {
return mod return mod
} }
mut errors := []string{} mut errors := []string{}
for server_url in default_vpm_server_urls {
for server_url in vpm_server_urls {
modurl := server_url + '/jsmod/$name' modurl := server_url + '/jsmod/$name'
verbose_println('Retrieving module metadata from: "$modurl" ...') verbose_println('Retrieving module metadata from: "$modurl" ...')
r := http.get(modurl) or { r := http.get(modurl) or {