Compare commits

..

10 Commits

Author SHA1 Message Date
repair-agent
7a6a519fbe fix: auto repair bugs #26, #25, #24
All checks were successful
Build and Deploy Backend / build-and-deploy (push) Successful in 3m13s
2026-02-24 16:19:40 +08:00
repair-agent
47be0781ac fix: auto repair bugs #23
All checks were successful
Build and Deploy Backend / build-and-deploy (push) Successful in 2m59s
2026-02-24 14:53:05 +08:00
repair-agent
d2af1ddaa9 fix: auto repair bugs #22
All checks were successful
Build and Deploy Backend / build-and-deploy (push) Successful in 3m18s
2026-02-24 14:43:23 +08:00
repair-agent
9144770130 fix(cicd): replace dead daocloud kubectl mirror with official k8s.io
All checks were successful
Build and Deploy Backend / build-and-deploy (push) Successful in 3m11s
DaoCloud mirror returns 404 for kubectl v1.28.2, causing Setup Kubectl
step to hang. Use official dl.k8s.io with cdn.dl.k8s.io as fallback.
Also update pinned dependency versions.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-24 14:38:16 +08:00
repair-agent
5fb71b99f9 fix: auto repair bugs #21, #20
All checks were successful
Build and Deploy Backend / build-and-deploy (push) Successful in 6m44s
2026-02-24 14:31:05 +08:00
repair-agent
c96bef3515 fix: auto repair bugs #19
Some checks failed
Build and Deploy Backend / build-and-deploy (push) Has been cancelled
2026-02-24 14:19:13 +08:00
repair-agent
f9857c17ee fix(deps): pin alibabacloud shared deps to avoid pip backtracking
Some checks failed
Build and Deploy Backend / build-and-deploy (push) Failing after 1m14s
dysmsapi and dypnsapi share alibabacloud-tea-openapi but their
transitive deps cause pip to endlessly backtrack during resolution.
Pin compatible versions of shared deps to speed up the build.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-24 14:10:19 +08:00
repair-agent
91d0311b95 fix: auto repair bugs #19
Some checks failed
Build and Deploy Backend / build-and-deploy (push) Failing after 1m32s
2026-02-24 13:53:03 +08:00
repair-agent
2628f7c281 fix: auto repair bugs #19
Some checks failed
Build and Deploy Backend / build-and-deploy (push) Failing after 1m0s
2026-02-24 13:47:42 +08:00
repair-agent
cbcf867b5b fix(cicd): use correct context field names for Log Center fingerprint
Some checks failed
Build and Deploy Backend / build-and-deploy (push) Failing after 54s
Add job_name and step_name to match Log Center's CI/CD fingerprint
generation, replacing failed_step which was not recognized. This fixes
deduplication causing new CI/CD failures to be silently dropped.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-24 13:46:08 +08:00
11 changed files with 118 additions and 10 deletions

24
.dockerignore Normal file
View File

@ -0,0 +1,24 @@
.git
.gitignore
.env
.env.example
.vscode
.idea
venv/
.venv/
__pycache__/
*.pyc
*.pyo
*.egg-info/
dist/
build/
*.log
*.sqlite3
media/
staticfiles/
.DS_Store
k8s/
.gitea/
docs/
CLAUDE.md
README.md

View File

@ -39,7 +39,8 @@ jobs:
- name: Setup Kubectl - name: Setup Kubectl
run: | run: |
curl -LO "https://files.m.daocloud.io/dl.k8s.io/release/v1.28.2/bin/linux/amd64/kubectl" curl -LO "https://dl.k8s.io/release/v1.28.2/bin/linux/amd64/kubectl" || \
curl -LO "https://cdn.dl.k8s.io/release/v1.28.2/bin/linux/amd64/kubectl"
chmod +x kubectl chmod +x kubectl
mv kubectl /usr/local/bin/ mv kubectl /usr/local/bin/
@ -118,11 +119,12 @@ jobs:
\"stack_trace\": [\"${ERROR_LOG}\"] \"stack_trace\": [\"${ERROR_LOG}\"]
}, },
\"context\": { \"context\": {
\"job_name\": \"build-and-deploy\",
\"step_name\": \"${FAILED_STEP}\",
\"workflow\": \"${{ github.workflow }}\", \"workflow\": \"${{ github.workflow }}\",
\"run_id\": \"${{ github.run_id }}\", \"run_id\": \"${{ github.run_id }}\",
\"branch\": \"${{ github.ref_name }}\", \"branch\": \"${{ github.ref_name }}\",
\"actor\": \"${{ github.actor }}\", \"actor\": \"${{ github.actor }}\",
\"failed_step\": \"${FAILED_STEP}\",
\"commit\": \"${{ github.sha }}\" \"commit\": \"${{ github.sha }}\"
} }
}" || true }" || true

View File

@ -28,4 +28,4 @@ COPY . /app/
EXPOSE 8000 EXPOSE 8000
# Run entrypoint # Run entrypoint
CMD ["gunicorn", "--bind", "0.0.0.0:8000", "config.wsgi:application"] CMD ["gunicorn", "--bind", "0.0.0.0:8000", "--workers", "2", "--timeout", "120", "--access-logfile", "-", "--error-logfile", "-", "config.wsgi:application"]

26
apps/devices/services.py Normal file
View File

@ -0,0 +1,26 @@
"""
设备模块服务层
"""
from .models import Device, UserDevice
class DeviceStatsService:
"""设备统计服务"""
@staticmethod
def get_bindrate(user):
"""获取用户设备绑定率"""
total_count = Device.objects.count()
if total_count == 0:
return {
'total_count': 0,
'bound_count': 0,
'bind_rate': 0,
}
bound_count = Device.objects.filter(status='bound').count()
bind_rate = bound_count / total_count * 100
return {
'total_count': total_count,
'bound_count': bound_count,
'bind_rate': round(bind_rate, 2),
}

View File

@ -120,7 +120,10 @@ class DeviceViewSet(viewsets.ViewSet):
} }
) )
# 更新设备状态 # 更新设备状态和可选的设备名称
device_name = request.data.get('device_name')
if device_name:
device.name = device_name
device.status = 'bound' device.status = 'bound'
device.save() device.save()

View File

@ -26,4 +26,6 @@ class Spirit(models.Model):
ordering = ['-created_at'] ordering = ['-created_at']
def __str__(self): def __str__(self):
if self.user_id is None:
return self.name
return f"{self.name} - {self.user.phone}" return f"{self.name} - {self.user.phone}"

View File

@ -7,8 +7,13 @@ URL configuration for RTC_DEMO project.
""" """
from django.contrib import admin from django.contrib import admin
from django.urls import path, include from django.urls import path, include
from django.http import JsonResponse
from drf_spectacular.views import SpectacularAPIView, SpectacularSwaggerView, SpectacularRedocView from drf_spectacular.views import SpectacularAPIView, SpectacularSwaggerView, SpectacularRedocView
def health_check(request):
return JsonResponse({"status": "ok"})
# ============ App端路由 (普通用户,手机一键登录) ============ # ============ App端路由 (普通用户,手机一键登录) ============
app_api_patterns = [ app_api_patterns = [
path('', include('apps.users.urls')), path('', include('apps.users.urls')),
@ -37,6 +42,9 @@ admin_api_patterns = [
] ]
urlpatterns = [ urlpatterns = [
# Health check (no auth, for K8s probes)
path('healthz/', health_check),
# Django Admin # Django Admin
path('django-admin/', admin.site.urls), path('django-admin/', admin.site.urls),

View File

@ -68,6 +68,22 @@ spec:
value: "https://qiyuan-log-center-api.airlabs.art" value: "https://qiyuan-log-center-api.airlabs.art"
- name: LOG_CENTER_ENABLED - name: LOG_CENTER_ENABLED
value: "true" value: "true"
livenessProbe:
httpGet:
path: /healthz/
port: 8000
initialDelaySeconds: 30
periodSeconds: 10
timeoutSeconds: 5
failureThreshold: 3
readinessProbe:
httpGet:
path: /healthz/
port: 8000
initialDelaySeconds: 15
periodSeconds: 5
timeoutSeconds: 3
failureThreshold: 3
resources: resources:
requests: requests:
memory: "256Mi" memory: "256Mi"

View File

@ -76,6 +76,22 @@ spec:
value: "https://qiyuan-log-center-api.airlabs.art" value: "https://qiyuan-log-center-api.airlabs.art"
- name: LOG_CENTER_ENABLED - name: LOG_CENTER_ENABLED
value: "true" value: "true"
livenessProbe:
httpGet:
path: /healthz/
port: 8000
initialDelaySeconds: 30
periodSeconds: 10
timeoutSeconds: 5
failureThreshold: 3
readinessProbe:
httpGet:
path: /healthz/
port: 8000
initialDelaySeconds: 15
periodSeconds: 5
timeoutSeconds: 3
failureThreshold: 3
resources: resources:
requests: requests:
memory: "256Mi" memory: "256Mi"

View File

@ -5,7 +5,7 @@ certifi==2026.1.4
cffi==2.0.0 cffi==2.0.0
charset-normalizer==3.4.4 charset-normalizer==3.4.4
crcmod==1.7 crcmod==1.7
cryptography==46.0.4 cryptography==44.0.3
Django==6.0.1 Django==6.0.1
django-cors-headers==4.9.0 django-cors-headers==4.9.0
djangorestframework==3.16.1 djangorestframework==3.16.1
@ -26,8 +26,16 @@ requests==2.32.5
six==1.17.0 six==1.17.0
sqlparse==0.5.5 sqlparse==0.5.5
urllib3==2.6.3 urllib3==2.6.3
python-dotenv==1.0.0
drf-spectacular==0.27.1 drf-spectacular==0.27.1
alibabacloud_dysmsapi20170525>=4.4.0 alibabacloud_dysmsapi20170525==4.4.0
alibabacloud_dypnsapi20170525>=3.0.0 alibabacloud_dypnsapi20170525==2.0.0
alibabacloud-tea-openapi==0.4.3
alibabacloud-tea-util==0.3.14
alibabacloud-credentials==1.0.2
alibabacloud-openapi-util==0.2.2
alibabacloud-gateway-spi==0.0.3
alibabacloud-endpoint-util==0.0.4
darabonba-core==1.0.5
volcengine-python-sdk[ark]>=5.0.9 volcengine-python-sdk[ark]>=5.0.9
edge-tts>=6.1.0 edge-tts>=6.1.0

View File

@ -6,7 +6,10 @@ import traceback
import threading import threading
import requests import requests
from rest_framework.views import exception_handler from rest_framework.views import exception_handler
from rest_framework.exceptions import AuthenticationFailed as DRFAuthenticationFailed
from rest_framework.exceptions import NotAuthenticated
from rest_framework import status from rest_framework import status
from rest_framework_simplejwt.exceptions import InvalidToken, AuthenticationFailed as JWTAuthenticationFailed
from utils.response import APIResponse from utils.response import APIResponse
@ -136,8 +139,8 @@ class ErrorCode:
def custom_exception_handler(exc, context): def custom_exception_handler(exc, context):
"""自定义异常处理器""" """自定义异常处理器"""
# 上报到 Log Center (仅上报非业务异常) # 上报到 Log Center (排除业务异常和认证异常,这些是正常业务流程)
if not isinstance(exc, BusinessException): if not isinstance(exc, (BusinessException, DRFAuthenticationFailed, NotAuthenticated, InvalidToken, JWTAuthenticationFailed)):
report_to_log_center(exc, context) report_to_log_center(exc, context)
# 处理业务异常 # 处理业务异常