From 929b637e8b64e9e32e6f87b4859c4ddf0dd87ec3 Mon Sep 17 00:00:00 2001 From: xianfuxing Date: Fri, 26 Apr 2019 14:59:01 +0800 Subject: [PATCH] add mosql device info update task --- apps/mosquito/tasks.py | 19 +++++++++++++++++-- mosqkiller/settings.py | 25 +++++++++++++++++++++++-- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/apps/mosquito/tasks.py b/apps/mosquito/tasks.py index 9af6ac7..fb6ce78 100644 --- a/apps/mosquito/tasks.py +++ b/apps/mosquito/tasks.py @@ -5,7 +5,8 @@ from datetime import datetime, time, timedelta from django.db.models import Max from celery import task from counter.models import DeviceCount -from mosquito.models import MosqPostStatistic, DevicePostStatistic, DeviceInfo +from counter.models import DeviceInfo as D1 +from mosquito.models import MosqPostStatistic, DevicePostStatistic, DeviceInfo, Org def max_count(x, y): @@ -121,4 +122,18 @@ def update_daily_statistic(): @task() def update_latest_statistic(): - pass \ No newline at end of file + pass + + +@task() +def update_mosq_device_info(): + """ 更新mosquito的DeviceInfo表""" + d1 = D1.objects.values('device_id', flat=True) + d2 = DeviceInfo.objects.values('device_id', flat=True) + s1 = set(d1) + s2 = set(d2) + x = s1 - s2 + + default_org = Org.objects.all().first() + for device_id in x: + DeviceInfo.objects.create(device_id=device_id, org=default_org) diff --git a/mosqkiller/settings.py b/mosqkiller/settings.py index c99563a..17b0a1b 100644 --- a/mosqkiller/settings.py +++ b/mosqkiller/settings.py @@ -211,8 +211,29 @@ CELERY_BEAT_SCHEDULE = { 'task': 'mosquito.tasks.update_daily_statistic', 'schedule': crontab(hour='*/1', minute=0), }, + 'update-mosq-device-info': { + 'task': 'mosquito.tasks.update_mosq_device_info', + 'schedule': crontab(hour='*/1', minute=0), + }, # 'update-latest-statistic': { # 'task': 'mosquito.tasks.update_latest_statistic', - # 'schedule': crontab(hour='*/1'), + # 'schedule': crontab(hour='*/1', minute=0), # }, -} \ No newline at end of file +} + +# logging db query +# LOGGING = { +# 'version': 1, +# 'disable_existing_loggers': False, +# 'handlers': { +# 'console': { +# 'class': 'logging.StreamHandler', +# }, +# }, +# 'loggers': { +# 'django.db.backends': { +# 'handlers': ['console'], +# 'level': 'DEBUG' if DEBUG else 'INFO', +# }, +# }, +# } \ No newline at end of file