Compare commits
10 Commits
47bc810256
...
7a6a519fbe
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7a6a519fbe | ||
|
|
47be0781ac | ||
|
|
d2af1ddaa9 | ||
|
|
9144770130 | ||
|
|
5fb71b99f9 | ||
|
|
c96bef3515 | ||
|
|
f9857c17ee | ||
|
|
91d0311b95 | ||
|
|
2628f7c281 | ||
|
|
cbcf867b5b |
24
.dockerignore
Normal file
24
.dockerignore
Normal 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
|
||||
@ -39,7 +39,8 @@ jobs:
|
||||
|
||||
- name: Setup Kubectl
|
||||
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
|
||||
mv kubectl /usr/local/bin/
|
||||
|
||||
@ -118,11 +119,12 @@ jobs:
|
||||
\"stack_trace\": [\"${ERROR_LOG}\"]
|
||||
},
|
||||
\"context\": {
|
||||
\"job_name\": \"build-and-deploy\",
|
||||
\"step_name\": \"${FAILED_STEP}\",
|
||||
\"workflow\": \"${{ github.workflow }}\",
|
||||
\"run_id\": \"${{ github.run_id }}\",
|
||||
\"branch\": \"${{ github.ref_name }}\",
|
||||
\"actor\": \"${{ github.actor }}\",
|
||||
\"failed_step\": \"${FAILED_STEP}\",
|
||||
\"commit\": \"${{ github.sha }}\"
|
||||
}
|
||||
}" || true
|
||||
|
||||
@ -28,4 +28,4 @@ COPY . /app/
|
||||
EXPOSE 8000
|
||||
|
||||
# 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
26
apps/devices/services.py
Normal 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),
|
||||
}
|
||||
@ -119,8 +119,11 @@ class DeviceViewSet(viewsets.ViewSet):
|
||||
'is_active': True
|
||||
}
|
||||
)
|
||||
|
||||
# 更新设备状态
|
||||
|
||||
# 更新设备状态和可选的设备名称
|
||||
device_name = request.data.get('device_name')
|
||||
if device_name:
|
||||
device.name = device_name
|
||||
device.status = 'bound'
|
||||
device.save()
|
||||
|
||||
|
||||
@ -26,4 +26,6 @@ class Spirit(models.Model):
|
||||
ordering = ['-created_at']
|
||||
|
||||
def __str__(self):
|
||||
if self.user_id is None:
|
||||
return self.name
|
||||
return f"{self.name} - {self.user.phone}"
|
||||
|
||||
@ -7,8 +7,13 @@ URL configuration for RTC_DEMO project.
|
||||
"""
|
||||
from django.contrib import admin
|
||||
from django.urls import path, include
|
||||
from django.http import JsonResponse
|
||||
from drf_spectacular.views import SpectacularAPIView, SpectacularSwaggerView, SpectacularRedocView
|
||||
|
||||
|
||||
def health_check(request):
|
||||
return JsonResponse({"status": "ok"})
|
||||
|
||||
# ============ App端路由 (普通用户,手机一键登录) ============
|
||||
app_api_patterns = [
|
||||
path('', include('apps.users.urls')),
|
||||
@ -37,6 +42,9 @@ admin_api_patterns = [
|
||||
]
|
||||
|
||||
urlpatterns = [
|
||||
# Health check (no auth, for K8s probes)
|
||||
path('healthz/', health_check),
|
||||
|
||||
# Django Admin
|
||||
path('django-admin/', admin.site.urls),
|
||||
|
||||
|
||||
@ -68,6 +68,22 @@ spec:
|
||||
value: "https://qiyuan-log-center-api.airlabs.art"
|
||||
- name: LOG_CENTER_ENABLED
|
||||
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:
|
||||
requests:
|
||||
memory: "256Mi"
|
||||
|
||||
@ -76,6 +76,22 @@ spec:
|
||||
value: "https://qiyuan-log-center-api.airlabs.art"
|
||||
- name: LOG_CENTER_ENABLED
|
||||
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:
|
||||
requests:
|
||||
memory: "256Mi"
|
||||
|
||||
@ -5,7 +5,7 @@ certifi==2026.1.4
|
||||
cffi==2.0.0
|
||||
charset-normalizer==3.4.4
|
||||
crcmod==1.7
|
||||
cryptography==46.0.4
|
||||
cryptography==44.0.3
|
||||
Django==6.0.1
|
||||
django-cors-headers==4.9.0
|
||||
djangorestframework==3.16.1
|
||||
@ -26,8 +26,16 @@ requests==2.32.5
|
||||
six==1.17.0
|
||||
sqlparse==0.5.5
|
||||
urllib3==2.6.3
|
||||
python-dotenv==1.0.0
|
||||
drf-spectacular==0.27.1
|
||||
alibabacloud_dysmsapi20170525>=4.4.0
|
||||
alibabacloud_dypnsapi20170525>=3.0.0
|
||||
alibabacloud_dysmsapi20170525==4.4.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
|
||||
edge-tts>=6.1.0
|
||||
|
||||
@ -6,7 +6,10 @@ import traceback
|
||||
import threading
|
||||
import requests
|
||||
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_simplejwt.exceptions import InvalidToken, AuthenticationFailed as JWTAuthenticationFailed
|
||||
from utils.response import APIResponse
|
||||
|
||||
|
||||
@ -136,8 +139,8 @@ class ErrorCode:
|
||||
|
||||
def custom_exception_handler(exc, context):
|
||||
"""自定义异常处理器"""
|
||||
# 上报到 Log Center (仅上报非业务异常)
|
||||
if not isinstance(exc, BusinessException):
|
||||
# 上报到 Log Center (排除业务异常和认证异常,这些是正常业务流程)
|
||||
if not isinstance(exc, (BusinessException, DRFAuthenticationFailed, NotAuthenticated, InvalidToken, JWTAuthenticationFailed)):
|
||||
report_to_log_center(exc, context)
|
||||
|
||||
# 处理业务异常
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user