#55 Celery parcel updating
* adds celery to project * adds celery background task for updating parcels * adds parcel calculation to creating of new geometries as well * tests outstanding!!!
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
# This will make sure the app is always imported when
|
||||
# Django starts so that shared_task will use this app.
|
||||
from .celery import app as celery_app
|
||||
|
||||
__all__ = ('celery_app',)
|
||||
|
||||
25
konova/celery.py
Normal file
25
konova/celery.py
Normal file
@@ -0,0 +1,25 @@
|
||||
import os
|
||||
|
||||
from celery import Celery
|
||||
|
||||
# Set the default Django settings module for the 'celery' program.
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'konova.settings')
|
||||
|
||||
app = Celery('konova')
|
||||
|
||||
# Using a string here means the worker doesn't have to serialize
|
||||
# the configuration object to child processes.
|
||||
# - namespace='CELERY' means all celery-related configuration keys
|
||||
# should have a `CELERY_` prefix.
|
||||
app.config_from_object('django.conf:settings', namespace='CELERY')
|
||||
|
||||
# Load task modules from all registered Django apps.
|
||||
app.autodiscover_tasks()
|
||||
|
||||
# Declare redis as broker
|
||||
app.conf.broker_url = 'redis://localhost:6379/0'
|
||||
|
||||
|
||||
@app.task(bind=True)
|
||||
def debug_task(self):
|
||||
print(f'Request: {self.request!r}')
|
||||
@@ -23,6 +23,7 @@ from django.utils.translation import gettext_lazy as _
|
||||
from konova.contexts import BaseContext
|
||||
from konova.models import BaseObject, Geometry, RecordableObjectMixin
|
||||
from konova.settings import DEFAULT_SRID
|
||||
from konova.tasks import celery_update_parcels
|
||||
from konova.utils.message_templates import FORM_INVALID
|
||||
from user.models import UserActionLogEntry
|
||||
|
||||
@@ -287,7 +288,7 @@ class SimpleGeomForm(BaseForm):
|
||||
geometry = self.instance.geometry
|
||||
geometry.geom = self.cleaned_data.get("geom", MultiPolygon(srid=DEFAULT_SRID))
|
||||
geometry.modified = action
|
||||
geometry.update_parcels()
|
||||
|
||||
geometry.save()
|
||||
except LookupError:
|
||||
# No geometry or linked instance holding a geometry exist --> create a new one!
|
||||
@@ -295,6 +296,8 @@ class SimpleGeomForm(BaseForm):
|
||||
geom=self.cleaned_data.get("geom", MultiPolygon(srid=DEFAULT_SRID)),
|
||||
created=action,
|
||||
)
|
||||
# Start the parcel update procedure in a background process
|
||||
celery_update_parcels.delay(geometry.id)
|
||||
return geometry
|
||||
|
||||
|
||||
|
||||
@@ -14,6 +14,12 @@ from django.utils.translation import gettext_lazy as _
|
||||
# Load other settings
|
||||
from konova.sub_settings.django_settings import *
|
||||
|
||||
proxy = "CHANGE_ME"
|
||||
PROXIES = {
|
||||
"http": proxy,
|
||||
"https": proxy,
|
||||
}
|
||||
|
||||
# ALLOWED FILE UPLOAD DEFINITIONS
|
||||
# Default: Upload into upper folder of code
|
||||
MEDIA_ROOT = BASE_DIR + "/.."
|
||||
|
||||
14
konova/tasks.py
Normal file
14
konova/tasks.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from celery import shared_task
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
|
||||
from konova.models import Geometry
|
||||
|
||||
|
||||
@shared_task
|
||||
def celery_update_parcels(geometry_id: str):
|
||||
try:
|
||||
geom = Geometry.objects.get(id=geometry_id)
|
||||
geom.parcels.clear()
|
||||
geom.update_parcels()
|
||||
except ObjectDoesNotExist:
|
||||
return
|
||||
@@ -3,6 +3,13 @@
|
||||
<h3>{% trans 'Spatial reference' %}</h3>
|
||||
</div>
|
||||
<div class="table-container w-100 scroll-300">
|
||||
{% if parcels|length == 0 %}
|
||||
<article class="alert alert-info">
|
||||
{% blocktrans %}
|
||||
If the geometry is not empty, the parcels are currently recalculated. Please refresh this page in a few moments.
|
||||
{% endblocktrans %}
|
||||
</article>
|
||||
{% else %}
|
||||
<table class="table table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
@@ -26,4 +33,5 @@
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
{% endif %}
|
||||
</div>
|
||||
@@ -11,7 +11,7 @@ import requests
|
||||
from django.contrib.auth.models import User
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from konova.settings import SSO_SERVER_BASE, SSO_PUBLIC_KEY
|
||||
from konova.settings import SSO_SERVER_BASE, SSO_PUBLIC_KEY, PROXIES
|
||||
from konova.sub_settings.context_settings import BASE_TITLE_SHORT
|
||||
|
||||
|
||||
@@ -52,7 +52,8 @@ class Messenger:
|
||||
requests.post(
|
||||
self.server_url,
|
||||
data=data,
|
||||
headers=headers
|
||||
headers=headers,
|
||||
proxies=PROXIES
|
||||
)
|
||||
|
||||
def send_object_checked(self, obj_identifier: str, performing_user: User, detail_view_url: str = ""):
|
||||
|
||||
@@ -12,7 +12,7 @@ import xmltodict
|
||||
from django.contrib.gis.db.models.functions import AsGML, Transform
|
||||
from requests.auth import HTTPDigestAuth
|
||||
|
||||
from konova.settings import DEFAULT_SRID_RLP, PARCEL_WFS_USER, PARCEL_WFS_PW
|
||||
from konova.settings import DEFAULT_SRID_RLP, PARCEL_WFS_USER, PARCEL_WFS_PW, PROXIES
|
||||
|
||||
|
||||
class AbstractWFSFetcher:
|
||||
@@ -148,7 +148,8 @@ class ParcelWFSFetcher(AbstractWFSFetcher):
|
||||
response = requests.post(
|
||||
url=self.base_url,
|
||||
data=post_body,
|
||||
auth=self.auth_digest_obj
|
||||
auth=self.auth_digest_obj,
|
||||
proxies=PROXIES,
|
||||
)
|
||||
|
||||
content = response.content.decode("utf-8")
|
||||
|
||||
Reference in New Issue
Block a user