InitController.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. # @Author : Rocky
  2. # @File : InitController.py
  3. # @Time : 2023/4/11 17:26
  4. from django.http import HttpResponse
  5. from django.views import View
  6. from Model.models import Device_Info, SceneLog
  7. from Object.RedisObject import RedisObject
  8. from Object.ResponseObject import ResponseObject
  9. class InitView(View):
  10. def get(self, request, *args, **kwargs):
  11. request.encoding = 'utf-8'
  12. operation = kwargs.get('operation')
  13. return self.validation(request.GET, operation)
  14. def post(self, request, *args, **kwargs):
  15. request.encoding = 'utf-8'
  16. operation = kwargs.get('operation')
  17. return self.validation(request.POST, operation)
  18. def validation(self, request_dict, operation):
  19. if operation == 'health-check': # 负载均衡器健康检测接口
  20. return self.health_check(request_dict)
  21. @staticmethod
  22. def health_check(request_dict):
  23. try:
  24. redis_obj = RedisObject()
  25. redis_obj.set_data('health_check', 1)
  26. response = ResponseObject()
  27. Device_Info.objects.filter().values('id').first()
  28. SceneLog.objects.filter().values('id').first()
  29. return response.json(0)
  30. except Exception as e:
  31. return HttpResponse(repr(e), status=500)