Commit 9b70534a authored by Felix Delattre's avatar Felix Delattre

Relied on very basic rule class

parent 93772488
Pipeline #18409 passed with stage
in 21 seconds
......@@ -19,10 +19,8 @@
import logging
import sys
# pylint: disable=import-error
from rabotnik import Rabotnik, Task
table_name = "test_table"
from rabotnik import Rabotnik # pylint: disable=import-error
from rules.building_demo import BuildingDemo # pylint: disable=import-error
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
......@@ -39,22 +37,8 @@ def building(building_id):
The payload is the *building_id*
"""
# At this point, the user can start her/hi processing routines.
# In this example we will be executing a set of rules that process
# data returned by a database query.
# A new celery task could be spawned for that:
recalculate_building_demo.apply_async(kwargs=dict(building_id=building_id))
@rabotnik.processor.task(name="recalculate_building_demo", base=Task)
def recalculate_building_demo(building_id):
"""A database task has access to the local database instance."""
db = recalculate_building_demo.database
for row in db.get_results("select * from %s" % table_name):
logger.info("data: %s" % str(row))
rules = [BuildingDemo(rabotnik.storage)]
rules[0].evaluate(building_id)
# Celery needs an exposed "app"
......
#!/usr/bin/env python3
# Copyright (c) 2020-2021:
# Helmholtz-Zentrum Potsdam Deutsches GeoForschungsZentrum GFZ
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
# General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see http://www.gnu.org/licenses/.
#!/usr/bin/env python3
# Copyright (c) 2020-2021:
# Helmholtz-Zentrum Potsdam Deutsches GeoForschungsZentrum GFZ
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
# General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see http://www.gnu.org/licenses/.
import logging
from rabotnik import Rule # pylint: disable=import-error
logger = logging.getLogger()
class BuildingDemo(Rule):
def __init__(self, db):
self.db = db
def evaluate(self, id: int):
"""A simple demo rule accessing a local database."""
for row in self.db.get_results("select * from test_table"):
logger.info("data: %s" % str(row))
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