diff --git a/billard/models.py b/billard/models.py index 0e6b7af..ae6d4ac 100644 --- a/billard/models.py +++ b/billard/models.py @@ -8,6 +8,7 @@ from django.db.models.signals import post_save from django.dispatch import receiver from django.core.mail import mail_admins from celery import shared_task +from .tasks import request_process_location_data class LocationData(models.Model): @@ -102,7 +103,7 @@ class Accounting(models.Model): @receiver(post_save, sender=LocationData) def test(sender, **kwargs): - process_location_data() + request_process_location_data.delay() @shared_task diff --git a/billard/tasks.py b/billard/tasks.py index 46d4a18..97a22ff 100644 --- a/billard/tasks.py +++ b/billard/tasks.py @@ -1,8 +1,9 @@ from __future__ import absolute_import, unicode_literals from celery import shared_task -from billard import utils +from django.conf import settings +import requests @shared_task -def process_location_data(): - utils.process_location_data() +def request_process_location_data(): + requests.get(url=settings.URL_LOCATION_PROCESSOR) diff --git a/billard/urls.py b/billard/urls.py index ebfd078..5f2c954 100644 --- a/billard/urls.py +++ b/billard/urls.py @@ -9,4 +9,5 @@ urlpatterns = [ url(r'^$', views.index, name='carom_index'), url(r'^(?P[0-9]+)/$', views.LocationDataDetailView.as_view(), name='detail'), url(r'api/v1/', include(router.urls)), + url(r'process_locationdata', views.process_locationdata, name='process_locationdata') ] diff --git a/billard/views.py b/billard/views.py index 1441290..839ba46 100644 --- a/billard/views.py +++ b/billard/views.py @@ -1,11 +1,12 @@ from billard.serializers import * -from .models import LocationData +from .models import LocationData, process_location_data from rest_framework import viewsets from django.shortcuts import render, redirect from django.views import generic from django.views.generic.detail import DetailView from django.contrib.auth.decorators import login_required from django.db.models import Min +from django.http import HttpResponse class LocationDataViewSet(viewsets.ModelViewSet): @@ -51,3 +52,8 @@ def index(request): resp = redirect('carom_index') resp['Location'] += '?loc={}'.format(str(loc)) return resp + + +def process_locationdata(request): + process_location_data() + return HttpResponse('DONE') diff --git a/caromserver/settings.py b/caromserver/settings.py index 043938d..e317b89 100644 --- a/caromserver/settings.py +++ b/caromserver/settings.py @@ -158,6 +158,8 @@ EMAIL_HOST_USER = '' EMAIL_HOST_PASSWORD = '' EMAIL_PORT = 25 +URL_LOCATION_PROCESSOR = 'http://127.0.0.1:8000/billard/process_locationdata' + STATIC_ROOT = "/srv/carom/carom-server/static/" try: