12345678910111213141516171819202122232425262728293031323334353637 |
- # @Author : Rocky
- # @File : InitController.py
- # @Time : 2023/4/11 17:26
- from django.http import HttpResponse
- from django.views import View
- from Model.models import Device_Info, SceneLog
- from Object.RedisObject import RedisObject
- from Object.ResponseObject import ResponseObject
- class InitView(View):
- def get(self, request, *args, **kwargs):
- request.encoding = 'utf-8'
- operation = kwargs.get('operation')
- return self.validation(request.GET, operation)
- def post(self, request, *args, **kwargs):
- request.encoding = 'utf-8'
- operation = kwargs.get('operation')
- return self.validation(request.POST, operation)
- def validation(self, request_dict, operation):
- if operation == 'health-check': # 负载均衡器健康检测接口
- return self.health_check(request_dict)
- @staticmethod
- def health_check(request_dict):
- try:
- redis_obj = RedisObject()
- response = ResponseObject()
- Device_Info.objects.filter().values('id').first()
- SceneLog.objects.filter().values('id').first()
- return response.json(0)
- except Exception as e:
- return HttpResponse(repr(e), status=500)
|