Commit b5797ede authored by gaoming's avatar gaoming

guangdiantong

parent 934eb572
......@@ -27,13 +27,19 @@ DEBUG = False
ALLOWED_HOSTS = ['*']
#**********************************Celery Config*************************************************
#**********************************Celery Config********************************************
CELERY_BROKER_URL = 'redis://:zi1jlhVHtH8MGNqB@172.17.40.145:6379/7' # Broker配置,使用Redis作为消息中间件
CELERY_RESULT_BACKEND = 'redis://:zi1jlhVHtH8MGNqB@172.17.40.145:6379/7' # BACKEND配置,这里使用redis
CELERY_RESULT_SERIALIZER = 'json' # 结果序列化方案
#***********************************************************************************
#************************************requests***********************************************
REQUESTS_CONNECT_TIMEOUT=5
REQUESTS_READ_TIMEOUT=5
#************************************requests***********************************************
# Application definition
......
......@@ -14,6 +14,7 @@ from django.views.decorators.csrf import csrf_exempt
from django.http import HttpResponseNotAllowed, JsonResponse, HttpResponse, Http404
from django.views.generic import View
from .models import *
from django.conf import settings
from celery import shared_task
from django.db.models import Q
......@@ -60,6 +61,7 @@ class Statistic(View):
platform=kwargs.get('platform','')
#time.sleep(2)
#设备编号相关id
device_id=kwargs.get('device_id')
......@@ -113,11 +115,11 @@ class Statistic(View):
#GET回调
if record.callback_type == CHANNEL_CALLBACK_TYPE.GET_CALLBACK.value[0]:
print(url)
response = requests.get(url)
response = requests.get(url, timeout=(settings.REQUESTS_CONNECT_TIMEOUT,settings.REQUESTS_READ_TIMEOUT))
#POST回调
if record.callback_type == CHANNEL_CALLBACK_TYPE.POST_CALLBACK.value[0]:
response = requests.post(url)
response = requests.post(url, timeout=(settings.REQUESTS_CONNECT_TIMEOUT,settings.REQUESTS_READ_TIMEOUT))
record.response=response.text;
record.save()
......@@ -174,17 +176,16 @@ class Channel(View):
#获得渠道数据
try:
data=Channel.__dict__.get(platform)(self)
data,success,fail=Channel.__dict__.get(platform)(self)
except Exception as e:
print(str(e))
return JsonResponse({'code':1,'failMsg':"not exists method to handle it!"})
result,msg=PromotionChannel.record(request,sub_name,**data)
if not result:
return JsonResponse({'code':1,'failMsg':msg})
return JsonResponse({"code":0,"failMsg":""})
return JsonResponse(fail(msg))
return JsonResponse(success(msg))
def zuimei(self):
......@@ -194,5 +195,20 @@ class Channel(View):
data=self.request.GET.dict()
data.update({"platform":data.pop('apptype',''),"appid":"jfq"})
return data
success =lambda msg:{"code":0,"failMsg":""}
fail =lambda msg:{'code':1,'failMsg':msg}
return data,success,fail
def guangdiantong(self):
'''
广点通(腾讯广告平台)
'''
data=self.request.GET.dict()
data.update({"device_id":data.pop('muid',''),"appid":"guangdiantong"})
success =lambda msg:{"ret":0,"failMsg":msg}
fail =lambda msg:{"ret":1,'failMsg':msg}
return data,success,fail
\ No newline at end of file
celery worker -A channels -l info
\ No newline at end of file
celery worker -A channels -l info
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment