问题描述
我正在使用 Django 后台任务。
但问题是有时无法正常工作。任务没有完成。有时该函数未被调用。
我的views.py
def process_tasks():
process_tasks_cmd = "python manage.py process_tasks"
process_tasks_args = shlex.split(process_tasks_cmd)
process_tasks_subprocess = subprocess.Popen(process_tasks_args,shell=True)
@api_view(["POST"])
@permission_classes([])
def test(request):
process_tasks()
fingerprint_sync(6,5,8)
return Response(result,status=status.HTTP_200_OK)
任务.py
@background(schedule=django.utils.timezone.Now())
def fingerprint_sync(EmployeeId,finger_activatn,device_code):
"""
FingerPrint Synchronization for employee
After Creating FingerPrint,Sync the FingerPrint data to all Device
Parameters:
EmployeeId: pk of employee
Returns:
Background Process Execute
if syncing not done- Data added to Synchronization table
"""
try:
logging.getLogger("info_logger").info("Triggered Fingerprint sync")
finger = FingerPrintInfo.objects.filter(~Q(FingerData=None),Employee=EmployeeId,Activation=finger_activatn)\
.order_by('FingerPrintId')
logging.getLogger("info_logger").info("Finger data filtered and arranged")
emp = Employee.objects.get(pk=EmployeeId)
data = {
"Employees": {
"EmployeeId": emp.EmployeeId,"EmployeeCode": emp.EmployeeCode,"EmployeeName": emp.EmployeeName,"EmployeeStatus": emp.EmployeeStatus
},"FingerPrintId": finger[3].FingerPrintId,"FingerData": bytes(finger[3].FingerData).decode("utf-8")
}
logging.getLogger("info_logger").info("Corresponding employee identified")
emp_device = Device.objects.filter(~Q(DeviceStatus=static_values["const0"]),~Q(DeviceCode=device_code))
for div in emp_device:
try:
device = Device.objects.get(pk=div.deviceid)
url = protocol + div.DeviceCode + device_api["API4"]
logging.getLogger("info_logger").info(url)
resp = requests.post(url,json=data)
logging.getLogger("info_logger").info(resp)
if not resp.text.__contains__('200'):
synchronization = Synchronization(
Employee=emp,Device=div,SyncType=selection_type["Fingerprint"]
)
synchronization.save()
except Exception as ex:
logging.getLogger("info_logger").info(repr(ex))
logging.getLogger("info_logger").info("Fingerprint not synced in " + div.DeviceCode)
except Exception as ex:
logging.getLogger("info_logger").info(repr(ex))
我的数据库数据
所有任务都在这里待处理..没有任务正在完成。
有人可以帮我吗
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)