add mosql device info update task
This commit is contained in:
parent
569b8c0f37
commit
929b637e8b
|
@ -5,7 +5,8 @@ from datetime import datetime, time, timedelta
|
||||||
from django.db.models import Max
|
from django.db.models import Max
|
||||||
from celery import task
|
from celery import task
|
||||||
from counter.models import DeviceCount
|
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):
|
def max_count(x, y):
|
||||||
|
@ -122,3 +123,17 @@ def update_daily_statistic():
|
||||||
@task()
|
@task()
|
||||||
def update_latest_statistic():
|
def update_latest_statistic():
|
||||||
pass
|
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)
|
||||||
|
|
|
@ -211,8 +211,29 @@ CELERY_BEAT_SCHEDULE = {
|
||||||
'task': 'mosquito.tasks.update_daily_statistic',
|
'task': 'mosquito.tasks.update_daily_statistic',
|
||||||
'schedule': crontab(hour='*/1', minute=0),
|
'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': {
|
# 'update-latest-statistic': {
|
||||||
# 'task': 'mosquito.tasks.update_latest_statistic',
|
# 'task': 'mosquito.tasks.update_latest_statistic',
|
||||||
# 'schedule': crontab(hour='*/1'),
|
# 'schedule': crontab(hour='*/1', minute=0),
|
||||||
# },
|
# },
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# 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',
|
||||||
|
# },
|
||||||
|
# },
|
||||||
|
# }
|
Loading…
Reference in New Issue