卡片不存在做额外处理/增加清除日志任务

This commit is contained in:
曹前明 2022-09-26 17:46:16 +08:00
parent cc2785d42e
commit 4d11516869
5 changed files with 45 additions and 4 deletions

View File

@ -1,6 +1,8 @@
from rest_framework.exceptions import ParseError, APIException
import logging
import time
from apps.hrm.models import ClockRecord, Employee
from apps.third.errors import DH_REQUEST_ERROR
from apps.third.models import TDevice
from apps.third.tapis import dhapis
from apps.third.clients import dhClient
@ -149,7 +151,7 @@ class HrmService:
"endDate": endDate
}
_, res = dhClient.request(**dhapis['card_add'], json=json_data)
time.sleep(10) # 等待确保生成卡片
time.sleep(8) # 等待确保生成卡片
cls.save(ep, data={'dh_face_card': cardNumber})
return cardNumber
@ -177,7 +179,14 @@ class HrmService:
"timeQuantumId": 1,
"cardPrivilegeDetails": details
}
dhClient.request(**dhapis['card_door_authority'], json=json_data)
is_ok, res = dhClient.request(**dhapis['card_door_authority'], json=json_data, raise_exception=False)
if is_ok == 'fail' and '44999999' in res['code']:
time.sleep(6)
dhClient.request(**dhapis['card_door_authority'], json=json_data)
elif is_ok == 'fail':
raise ParseError(**res)
elif is_ok == 'error':
raise APIException(**DH_REQUEST_ERROR)
cls.save(ep, data={'dh_dchannels': dh_dchannels})
return dh_dchannels

View File

@ -1,4 +1,18 @@
# Create your tasks here
from __future__ import absolute_import, unicode_literals
from datetime import timedelta
from apps.monitor.models import DrfRequestLog
from apps.utils.tasks import CustomTask
from celery import shared_task
from django.utils import timezone
@shared_task(base=CustomTask)
def clear_drf_log():
"""清除7天前的日志记录
清除7天前的日志记录
"""
now = timezone.now()
days7_ago = now - timedelta(days=7)
DrfRequestLog.objects.filter(create_time__lte=days7_ago).delete()

View File

@ -92,7 +92,7 @@ class DhClient:
self.handle_log(result='fail', response=ret)
if raise_exception:
raise ParseError(**err_detail)
return 'fail', dict(detail=detail, code='dh_'+str(ret['code']))
return 'fail', err_detail
# self.handle_log(result='success', response=ret) # 成功的日志就不记录了
return 'success', ret['data'] if 'data' in ret else None

View File

@ -86,7 +86,7 @@ class SpClient:
self.handle_log(result='fail', response=ret)
if raise_exception:
raise ParseError(**err_detail)
return 'fail', dict(detail=detail, code='sp_'+str(ret['code']))
return 'fail', err_detail
# self.handle_log(result='success', response=ret)
return 'success', ret
self.handle_log(result='error', errors=traceback.format_exc())

18
apps/third/tasks.py Normal file
View File

@ -0,0 +1,18 @@
# Create your tasks here
from __future__ import absolute_import, unicode_literals
from datetime import timedelta
from apps.utils.tasks import CustomTask
from apps.third.models import Tlog
from celery import shared_task
from django.utils import timezone
@shared_task(base=CustomTask)
def clear_tlog():
"""清除7天前的日志记录
清除7天前的日志记录
"""
now = timezone.now()
days7_ago = now - timedelta(days=7)
Tlog.objects.filter(create_time__lte=days7_ago).delete()