source: src/mapservice/server_impl/CeleryWorker.py@ a249e2d

debian/bullseye
Last change on this file since a249e2d was ae2ff15, checked in by Joachim Langenbach <joachim.langenbach@…>, 7 years ago
  • Fixed testing environment
    • Fixed some issues in the API and it's serving
  • Property mode set to 100644
File size: 2.3 KB
RevLine 
[a88607b]1'''
2 Copyright (C) 2020 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16'''
17from celery import Celery
18import flask
19from sqlalchemy import event
20
[096625e]21from . import config_object, app, application, celery, setup_app
[a88607b]22from .database.Model import db
23from .tasks import tasks
24
25# see https://flask.palletsprojects.com/en/1.1.x/patterns/celery/
26def setup_celery(flask_app, celery_app):
27 celery_app.conf.update(flask_app.config)
28 TaskBase = celery_app.Task
29
30 class ContextTask(TaskBase):
31 abstract = True
32
33 def __call__(self, *args, **kwargs):
34 with flask_app.app_context():
35 @event.listens_for(db.engine, "connect")
36 def load_spatialite(dbapi_conn, connection_record):
37 if 'sqlite' in flask.current_app.config['SQLALCHEMY_DATABASE_URI']:
38 # From https://geoalchemy-2.readthedocs.io/en/latest/spatialite_tutorial.html
39 dbapi_conn.enable_load_extension(True)
40 dbapi_conn.load_extension('/usr/local/lib64/mod_spatialite')
41
42 return TaskBase.__call__(self, *args, **kwargs)
43
44 celery_app.Task = ContextTask
45
[ce301d3]46 with flask_app.app_context():
47 if not 'TILES_LITTLE_ZOOM_SCHEDULE' in flask.current_app.config:
48 flask.current_app.logger.error('TILES_LITTLE_ZOOM_SCHEDULE not configured')
49 raise ImportError('TILES_LITTLE_ZOOM_SCHEDULE not configured')
50 tiles_little_zoom_schedule = flask.current_app.config['TILES_LITTLE_ZOOM_SCHEDULE']
51
52 celery_app.conf.beat_schedule = {
53 'add-log_little_zoom_slice': {
[adda9f2]54 'task': 'gnuboat_mapservice.server_impl.tasks.tasks.log_little_zoom_slice',
[ce301d3]55 'schedule': tiles_little_zoom_schedule
56 },
57 }
58
[a88607b]59 return celery_app
60
[096625e]61setup_app('GNUBoat Celery Worker', config_object)
[a88607b]62setup_celery(application, celery)
Note: See TracBrowser for help on using the repository browser.