reenable request processor

This commit is contained in:
Robert Einsle 2017-02-11 18:59:42 +01:00
parent 0b1c7675f0
commit e84b2f54a9
5 changed files with 16 additions and 5 deletions

View File

@ -8,6 +8,7 @@ from django.db.models.signals import post_save
from django.dispatch import receiver from django.dispatch import receiver
from django.core.mail import mail_admins from django.core.mail import mail_admins
from celery import shared_task from celery import shared_task
from .tasks import request_process_location_data
class LocationData(models.Model): class LocationData(models.Model):
@ -102,7 +103,7 @@ class Accounting(models.Model):
@receiver(post_save, sender=LocationData) @receiver(post_save, sender=LocationData)
def test(sender, **kwargs): def test(sender, **kwargs):
process_location_data() request_process_location_data.delay()
@shared_task @shared_task

View File

@ -1,8 +1,9 @@
from __future__ import absolute_import, unicode_literals from __future__ import absolute_import, unicode_literals
from celery import shared_task from celery import shared_task
from billard import utils from django.conf import settings
import requests
@shared_task @shared_task
def process_location_data(): def request_process_location_data():
utils.process_location_data() requests.get(url=settings.URL_LOCATION_PROCESSOR)

View File

@ -9,4 +9,5 @@ urlpatterns = [
url(r'^$', views.index, name='carom_index'), url(r'^$', views.index, name='carom_index'),
url(r'^(?P<pk>[0-9]+)/$', views.LocationDataDetailView.as_view(), name='detail'), url(r'^(?P<pk>[0-9]+)/$', views.LocationDataDetailView.as_view(), name='detail'),
url(r'api/v1/', include(router.urls)), url(r'api/v1/', include(router.urls)),
url(r'process_locationdata', views.process_locationdata, name='process_locationdata')
] ]

View File

@ -1,11 +1,12 @@
from billard.serializers import * from billard.serializers import *
from .models import LocationData from .models import LocationData, process_location_data
from rest_framework import viewsets from rest_framework import viewsets
from django.shortcuts import render, redirect from django.shortcuts import render, redirect
from django.views import generic from django.views import generic
from django.views.generic.detail import DetailView from django.views.generic.detail import DetailView
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from django.db.models import Min from django.db.models import Min
from django.http import HttpResponse
class LocationDataViewSet(viewsets.ModelViewSet): class LocationDataViewSet(viewsets.ModelViewSet):
@ -51,3 +52,8 @@ def index(request):
resp = redirect('carom_index') resp = redirect('carom_index')
resp['Location'] += '?loc={}'.format(str(loc)) resp['Location'] += '?loc={}'.format(str(loc))
return resp return resp
def process_locationdata(request):
process_location_data()
return HttpResponse('DONE')

View File

@ -158,6 +158,8 @@ EMAIL_HOST_USER = ''
EMAIL_HOST_PASSWORD = '' EMAIL_HOST_PASSWORD = ''
EMAIL_PORT = 25 EMAIL_PORT = 25
URL_LOCATION_PROCESSOR = 'http://127.0.0.1:8000/billard/process_locationdata'
STATIC_ROOT = "/srv/carom/carom-server/static/" STATIC_ROOT = "/srv/carom/carom-server/static/"
try: try: