Code Farm: per-plot auto-replant pause and crop-lock check; community sync and node work
DevPlace CI / test (push) Failing after 44m45s
DevPlace CI / test (push) Failing after 44m45s
Continuous Delivery could never be turned off once a crop was planted. Add a one-shot per-plot "stop after harvest" flag (POST /game/plot/stop, Devii tool game_plot_stop, game_plots.stop_after_harvest), cleared by the next plant, autoreplant claim or Refactor. Autoreplant now also respects crop locks through the shared _crop_lock predicate. Plan and measurements in happyplanting.md. Also includes the pending community sync, node network and related work in the tree; the full suite passed (4999) with all of it. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -17,24 +17,35 @@ from devplacepy.database.nodes import (
|
||||
add_event,
|
||||
count_open_requests,
|
||||
device_breakdown,
|
||||
cache_stats,
|
||||
effective_status,
|
||||
get_device,
|
||||
lifetime_counters,
|
||||
list_flags,
|
||||
load_circuits,
|
||||
recent_devices,
|
||||
request_status_counts,
|
||||
resolve_flag,
|
||||
set_class_override,
|
||||
suspend_device,
|
||||
unsuspend_device,
|
||||
usage_day_totals,
|
||||
)
|
||||
from devplacepy.dependencies import json_or_form
|
||||
from devplacepy.models import AdminNodeKillswitchForm, AdminNodeSettingsForm, AdminNodeSuspendForm
|
||||
from devplacepy.models import (
|
||||
AdminNodeClassForm,
|
||||
AdminNodeKillswitchForm,
|
||||
AdminNodeSettingsForm,
|
||||
AdminNodeSuspendForm,
|
||||
)
|
||||
from devplacepy.responses import action_result, json_error, respond
|
||||
from devplacepy.routers.admin._shared import deny_senior, is_senior_admin
|
||||
from devplacepy.routers.nodes.social import SOCIAL_DAILY_DEFAULT
|
||||
from devplacepy.schemas import (
|
||||
AdminNodeCircuitOut,
|
||||
AdminNodeDeviceOut,
|
||||
AdminNodeFlagOut,
|
||||
AdminNodeOutcomeOut,
|
||||
AdminNodePoolOut,
|
||||
AdminNodeQueueOut,
|
||||
AdminNodeSettingOut,
|
||||
@@ -43,6 +54,9 @@ from devplacepy.schemas import (
|
||||
from devplacepy.seo import base_seo_context, site_url, website_schema
|
||||
from devplacepy.services.audit import record as audit
|
||||
from devplacepy.services.base import BaseService
|
||||
from devplacepy.services.nodes.circuit import CircuitBreaker
|
||||
from devplacepy.services.nodes.geo import shared_geo
|
||||
from devplacepy.services.nodes.registry import OUTCOME_PREFIX
|
||||
from devplacepy.utils import not_found, require_admin
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -81,6 +95,8 @@ SETTING_FIELDS: tuple[NodeSettingField, ...] = (
|
||||
NodeSettingField("nodes_cache_ttl_seconds", "Result cache lifetime (seconds)", LIMITS.cache_ttl_seconds, LIMITS.cache_ttl_seconds),
|
||||
NodeSettingField("nodes_daily_social_user", "Daily social searches per member", SOCIAL_DAILY_DEFAULT, QUOTA_SOCIAL_CEILING),
|
||||
NodeSettingField("nodes_social_via_nodes", "Route social search through nodes", 0, None, "flag"),
|
||||
NodeSettingField("nodes_allow_unknown_class", "Allow donors whose address class is unknown", 0, None, "flag"),
|
||||
NodeSettingField("nodes_redundancy_percent", "Redundancy sample of fetch jobs (percent)", LIMITS.redundancy_percent, LIMITS.redundancy_max_percent),
|
||||
)
|
||||
SETTING_FIELDS_BY_KEY = {field.key: field for field in SETTING_FIELDS}
|
||||
|
||||
@@ -151,6 +167,8 @@ def device_views(rows: list[dict], owners: dict) -> list[AdminNodeDeviceOut]:
|
||||
suspend_reason=row.get("suspend_reason") or "",
|
||||
country=row.get("country") or "",
|
||||
asn_class=row.get("asn_class") or "unknown",
|
||||
asn=row.get("asn") or "",
|
||||
class_override=row.get("class_override") or "",
|
||||
last_seen_at=row.get("last_seen_at") or None,
|
||||
created_at=row.get("created_at"),
|
||||
owner_uid=row.get("user_uid") or "",
|
||||
@@ -177,7 +195,44 @@ def flag_views(rows: list[dict], owners: dict, devices: dict) -> list[AdminNodeF
|
||||
]
|
||||
|
||||
|
||||
def circuit_views() -> list[AdminNodeCircuitOut]:
|
||||
now = datetime.now(timezone.utc).timestamp()
|
||||
breaker = CircuitBreaker()
|
||||
views = []
|
||||
for row in load_circuits():
|
||||
age = max(0.0, now - float(row.get("opened_at") or 0.0))
|
||||
failures = int(row.get("failures") or 0)
|
||||
if failures < breaker.failures:
|
||||
state, left = "closed", 0
|
||||
elif age < breaker.open_seconds:
|
||||
state, left = "open", int(breaker.open_seconds - age)
|
||||
else:
|
||||
state, left = "half_open", 0
|
||||
views.append(AdminNodeCircuitOut(key=row["key"], state=state, failures=failures, seconds_left=left))
|
||||
return views
|
||||
|
||||
|
||||
def outcome_views(counters: dict[str, int]) -> list[AdminNodeOutcomeOut]:
|
||||
grouped: dict[tuple[str, str], dict[str, int]] = {}
|
||||
for name, value in counters.items():
|
||||
_, adapter, asn_class, kind = name.split(":")
|
||||
grouped.setdefault((adapter, asn_class), {})[kind] = value
|
||||
return [
|
||||
AdminNodeOutcomeOut(
|
||||
adapter=adapter,
|
||||
asn_class=asn_class,
|
||||
ok=kinds.get("ok", 0),
|
||||
blocked=kinds.get("blocked", 0),
|
||||
failed=kinds.get("failed", 0),
|
||||
total=sum(kinds.values()),
|
||||
)
|
||||
for (adapter, asn_class), kinds in sorted(grouped.items())
|
||||
]
|
||||
|
||||
|
||||
def overview() -> dict:
|
||||
lifetime = lifetime_counters()
|
||||
outcomes = {name: value for name, value in lifetime.items() if name.startswith(OUTCOME_PREFIX)}
|
||||
devices = recent_devices(ADMIN_LIST_LIMIT)
|
||||
flags = list_flags()[:ADMIN_LIST_LIMIT]
|
||||
device_by_uid = {row["uid"]: row for row in devices}
|
||||
@@ -199,6 +254,11 @@ def overview() -> dict:
|
||||
"devices": device_views(devices, owners),
|
||||
"settings": settings_view(),
|
||||
"limits": LIMITS.describe(),
|
||||
"circuits": circuit_views(),
|
||||
"outcomes": outcome_views(outcomes),
|
||||
"lifetime": {name: value for name, value in lifetime.items() if name not in outcomes},
|
||||
"geo": shared_geo().status(),
|
||||
"cache": cache_stats(),
|
||||
"admin_section": "nodes",
|
||||
}
|
||||
|
||||
@@ -328,6 +388,39 @@ async def admin_nodes_suspend(
|
||||
return action_result(request, LIST_URL, data={"uid": device_uid, "minutes": data.minutes})
|
||||
|
||||
|
||||
@router.post("/nodes/devices/{device_uid}/class")
|
||||
async def admin_nodes_class(
|
||||
request: Request,
|
||||
device_uid: str,
|
||||
data: Annotated[AdminNodeClassForm, Depends(json_or_form(AdminNodeClassForm))],
|
||||
):
|
||||
admin = require_admin(request)
|
||||
device = require_device(device_uid)
|
||||
owner = owner_of(device)
|
||||
if is_senior_admin(admin, owner):
|
||||
return deny_senior(request, admin, owner["uid"], owner, "node.device.override", LIST_URL)
|
||||
value = "allow" if data.value == "allow" else ""
|
||||
before = device.get("class_override") or ""
|
||||
set_class_override(device_uid, value)
|
||||
audit.record(
|
||||
request,
|
||||
"node.device.override",
|
||||
user=admin,
|
||||
target_type="node_device",
|
||||
target_uid=device_uid,
|
||||
target_label=device.get("label") or device_uid,
|
||||
old_value=before,
|
||||
new_value=value,
|
||||
metadata={"owner_uid": device.get("user_uid"), "asn_class": device.get("asn_class") or "unknown"},
|
||||
summary=(
|
||||
f"admin {admin['username']} {'allowed' if value else 'cleared the override for'} "
|
||||
f"node device {device.get('label') or device_uid} regardless of its address class"
|
||||
),
|
||||
links=[audit.target("user", device.get("user_uid"), (owner or {}).get("username"))],
|
||||
)
|
||||
return action_result(request, LIST_URL, data={"uid": device_uid, "class_override": value})
|
||||
|
||||
|
||||
@router.post("/nodes/devices/{device_uid}/unsuspend")
|
||||
async def admin_nodes_unsuspend(request: Request, device_uid: str):
|
||||
admin = require_admin(request)
|
||||
|
||||
Reference in New Issue
Block a user