Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6340309e66 | ||
|
|
f9ccb7bfd6 |
@@ -161,6 +161,10 @@ def page(db: Session, q: str = "", status: str = "", offset: int = 0, limit: int
|
||||
return payload
|
||||
|
||||
|
||||
def _elapsed_ms(started: float) -> int:
|
||||
return max(0, int((time.perf_counter() - started) * 1000))
|
||||
|
||||
|
||||
def probe(scheme: str, host: str, port: int) -> tuple[bool, int, str]:
|
||||
url = build_proxy_url(scheme, host, port)
|
||||
samples: list[int] = []
|
||||
@@ -176,19 +180,19 @@ def probe(scheme: str, host: str, port: int) -> tuple[bool, int, str]:
|
||||
started = time.perf_counter()
|
||||
try:
|
||||
response = client.get(target)
|
||||
latency = int((time.perf_counter() - started) * 1000)
|
||||
latency = _elapsed_ms(started)
|
||||
if response.status_code >= 500:
|
||||
samples.append(max(latency, LATENCY_LIMIT_MS))
|
||||
samples.append(latency)
|
||||
reasons.append(f"HTTP {response.status_code}")
|
||||
continue
|
||||
samples.append(latency)
|
||||
except Exception as exc:
|
||||
samples.append(int((time.perf_counter() - started) * 1000) or LATENCY_LIMIT_MS)
|
||||
samples.append(_elapsed_ms(started))
|
||||
reasons.append(_short_reason(exc))
|
||||
except Exception as exc:
|
||||
return False, LATENCY_LIMIT_MS, _short_reason(exc)
|
||||
return False, 0, _short_reason(exc)
|
||||
if not samples:
|
||||
return False, LATENCY_LIMIT_MS, reasons[0] if reasons else "无法连接"
|
||||
return False, 0, reasons[0] if reasons else "无法连接"
|
||||
average = int(round(sum(samples) / len(samples)))
|
||||
if reasons:
|
||||
return False, average, reasons[0]
|
||||
@@ -431,7 +435,7 @@ def _probe_many(nodes: list[tuple[int, str, str, int]]) -> list[tuple[int, bool,
|
||||
try:
|
||||
ok, latency, reason = future.result()
|
||||
except Exception as exc:
|
||||
ok, latency, reason = False, LATENCY_LIMIT_MS, _short_reason(exc)
|
||||
ok, latency, reason = False, 0, _short_reason(exc)
|
||||
results.append((node_id, ok, latency, reason))
|
||||
return results
|
||||
|
||||
|
||||
@@ -219,6 +219,29 @@ def test_probe_averages_euniv_related_sites(monkeypatch) -> None:
|
||||
assert reason == ""
|
||||
|
||||
|
||||
def test_probe_instant_connect_error_keeps_elapsed_latency(monkeypatch) -> None:
|
||||
class FakeClient:
|
||||
def __init__(self, **_kwargs) -> None:
|
||||
return None
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
||||
def __exit__(self, *_args) -> bool:
|
||||
return False
|
||||
|
||||
def get(self, _url: str):
|
||||
raise httpx.ConnectError("boom")
|
||||
|
||||
ticks = iter([0.0, 0.012, 0.012, 0.018, 0.018, 0.025])
|
||||
monkeypatch.setattr("euniv.proxy_pool.httpx.Client", FakeClient)
|
||||
monkeypatch.setattr("euniv.proxy_pool.time.perf_counter", lambda: next(ticks))
|
||||
ok, latency, reason = probe("socks4", "10.0.0.9", 1080)
|
||||
assert ok is False
|
||||
assert latency == 8
|
||||
assert reason == "无法连接"
|
||||
|
||||
|
||||
def test_admin_can_probe_one_and_all_proxies(monkeypatch) -> None:
|
||||
import euniv.api as api_module
|
||||
|
||||
|
||||
@@ -323,7 +323,9 @@ onUnmounted(() => stopPoll());
|
||||
</span>
|
||||
<template v-else>{{ formatLatency(row.latency_ms) }}</template>
|
||||
</td>
|
||||
<td :class="statusClass(row)">{{ row.status_text }}</td>
|
||||
<td :class="statusClass(row)" :title="row.note || undefined">
|
||||
{{ row.status_text }}<template v-if="row.note"> · {{ row.note }}</template>
|
||||
</td>
|
||||
<td class="when">{{ formatTime(row.last_checked_at) || "—" }}</td>
|
||||
<td>
|
||||
<n-button
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from "vue";
|
||||
import { NAlert, NButton, NCheckbox, NDropdown, NForm, NFormItem, NIcon, NInput, NInputNumber, NModal, NSelect, NTimePicker, NTooltip, useDialog, type DropdownOption } from "naive-ui";
|
||||
import { EllipsisHorizontalOutline, EllipsisVerticalOutline, PauseOutline, PlayOutline, SettingsOutline, WarningOutline } from "@vicons/ionicons5";
|
||||
import { dayOptions, workerOptions } from "../../shared/studyFields";
|
||||
import { EllipsisHorizontalOutline, EllipsisVerticalOutline, HelpCircleOutline, PauseOutline, PlayOutline, SettingsOutline, WarningOutline } from "@vicons/ionicons5";
|
||||
import { dayOptions, workerHint, workerOptions } from "../../shared/studyFields";
|
||||
|
||||
interface UserRow {
|
||||
employee_id: string;
|
||||
@@ -724,8 +724,21 @@ onMounted(() => {
|
||||
<n-time-picker v-model:formatted-value="startTime" value-format="HH:mm:ss" :actions="null" />
|
||||
</div>
|
||||
</n-form-item>
|
||||
<n-form-item label="线程数量">
|
||||
<n-select id="admin-course-workers" v-model:value="workersValue" :options="workerOptions" />
|
||||
<n-form-item>
|
||||
<template #label>
|
||||
<span class="field-title">
|
||||
<span>线程数量</span>
|
||||
<n-tooltip placement="top">
|
||||
<template #trigger>
|
||||
<button type="button" class="hint-icon" aria-label="说明">
|
||||
<n-icon><HelpCircleOutline /></n-icon>
|
||||
</button>
|
||||
</template>
|
||||
{{ workerHint }}
|
||||
</n-tooltip>
|
||||
</span>
|
||||
</template>
|
||||
<n-select id="admin-course-workers" class="worker-select" v-model:value="workersValue" :options="workerOptions" />
|
||||
</n-form-item>
|
||||
<n-form-item label="代理类型">
|
||||
<n-select v-model:value="proxyScheme" :options="proxyOptions" />
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, onUnmounted, ref, watch } from "vue";
|
||||
import { NAlert, NButton, NForm, NFormItem, NIcon, NInput, NInputNumber, NModal, NProgress, NSelect, NTimePicker, NTooltip } from "naive-ui";
|
||||
import { GlobeOutline, PlayOutline, RefreshOutline, StopOutline, WarningOutline } from "@vicons/ionicons5";
|
||||
import { dayOptions, workerOptions } from "../../shared/studyFields";
|
||||
import { GlobeOutline, HelpCircleOutline, PlayOutline, RefreshOutline, StopOutline, WarningOutline } from "@vicons/ionicons5";
|
||||
import { dayOptions, workerHint, workerOptions } from "../../shared/studyFields";
|
||||
|
||||
interface HomeSummary {
|
||||
name: string;
|
||||
@@ -551,17 +551,23 @@ onUnmounted(() => {
|
||||
<section class="panel-card study-card">
|
||||
<header class="panel-card-head">
|
||||
<h3>自动学习</h3>
|
||||
<n-button
|
||||
:type="studyControl.started ? 'error' : 'primary'"
|
||||
size="small"
|
||||
:loading="studyBusy"
|
||||
@click="toggleStudy"
|
||||
>
|
||||
<template #icon>
|
||||
<n-icon><StopOutline v-if="studyControl.started" /><PlayOutline v-else /></n-icon>
|
||||
</template>
|
||||
{{ studyControl.started ? "停止" : "立即开始" }}
|
||||
</n-button>
|
||||
<div class="study-head-actions">
|
||||
<n-button v-if="proxyLoaded" size="small" quaternary @click="proxyOpen = true">
|
||||
<template #icon><n-icon><GlobeOutline /></n-icon></template>
|
||||
代理
|
||||
</n-button>
|
||||
<n-button
|
||||
:type="studyControl.started ? 'error' : 'primary'"
|
||||
size="small"
|
||||
:loading="studyBusy"
|
||||
@click="toggleStudy"
|
||||
>
|
||||
<template #icon>
|
||||
<n-icon><StopOutline v-if="studyControl.started" /><PlayOutline v-else /></n-icon>
|
||||
</template>
|
||||
{{ studyControl.started ? "停止" : "立即开始" }}
|
||||
</n-button>
|
||||
</div>
|
||||
</header>
|
||||
<n-alert v-if="studyError" class="summary-error" type="error">{{ studyError }}</n-alert>
|
||||
<n-form class="compact-nform" label-placement="left" label-align="left" :label-width="96" :show-feedback="false" size="small">
|
||||
@@ -591,8 +597,21 @@ onUnmounted(() => {
|
||||
<n-time-picker v-model:formatted-value="startTime" value-format="HH:mm:ss" size="small" :actions="null" />
|
||||
</div>
|
||||
</n-form-item>
|
||||
<n-form-item v-if="workersLoaded" label="线程数量">
|
||||
<n-select id="course-workers" v-model:value="courseWorkers" size="small" :options="workerOptions" />
|
||||
<n-form-item v-if="workersLoaded">
|
||||
<template #label>
|
||||
<span class="field-title">
|
||||
<span>线程数量</span>
|
||||
<n-tooltip placement="top">
|
||||
<template #trigger>
|
||||
<button type="button" class="hint-icon" aria-label="说明">
|
||||
<n-icon><HelpCircleOutline /></n-icon>
|
||||
</button>
|
||||
</template>
|
||||
{{ workerHint }}
|
||||
</n-tooltip>
|
||||
</span>
|
||||
</template>
|
||||
<n-select id="course-workers" class="worker-select" v-model:value="courseWorkers" size="small" :options="workerOptions" />
|
||||
</n-form-item>
|
||||
</n-form>
|
||||
<div class="home-study-status">
|
||||
@@ -612,12 +631,6 @@ onUnmounted(() => {
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
<div class="study-card-foot">
|
||||
<n-button v-if="proxyLoaded" size="small" quaternary @click="proxyOpen = true">
|
||||
<template #icon><n-icon><GlobeOutline /></n-icon></template>
|
||||
代理
|
||||
</n-button>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
<n-modal
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
export const workerHint = "速度较慢,但是稳定且不容易触发风控,最大可设置8";
|
||||
|
||||
export const workerOptions = [
|
||||
{ label: "1 · 推荐,速度较慢,稳定且不容易触发风控", value: 1 },
|
||||
{ label: "1 · 推荐", value: 1 },
|
||||
{ label: "2", value: 2 },
|
||||
{ label: "3", value: 3 },
|
||||
{ label: "4", value: 4 },
|
||||
|
||||
+11
-6
@@ -562,6 +562,17 @@ select {
|
||||
width: 108px;
|
||||
}
|
||||
|
||||
.worker-select {
|
||||
width: 148px;
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
.study-head-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.start-control .n-time-picker {
|
||||
width: 148px;
|
||||
}
|
||||
@@ -680,12 +691,6 @@ select {
|
||||
box-shadow: 0 0 6px rgba(248, 81, 73, 0.5);
|
||||
}
|
||||
|
||||
.study-card-foot {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
margin-top: 12px;
|
||||
}
|
||||
|
||||
.history-facts {
|
||||
grid-template-columns: repeat(4, minmax(0, 1fr));
|
||||
margin: 0 0 16px;
|
||||
|
||||
Reference in New Issue
Block a user