Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Dynamic Exposure
rabotnik
rabotnik-demo
Commits
9b70534a
Commit
9b70534a
authored
Jan 14, 2021
by
Felix Delattre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Relied on very basic rule class
parent
93772488
Pipeline
#18409
passed with stage
in 21 seconds
Changes
3
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
55 additions
and
20 deletions
+55
-20
data/instance-b/instance.py
data/instance-b/instance.py
+4
-20
data/instance-b/rules/__init__.py
data/instance-b/rules/__init__.py
+17
-0
data/instance-b/rules/building_demo.py
data/instance-b/rules/building_demo.py
+34
-0
No files found.
data/instance-b/instance.py
View file @
9b70534a
...
...
@@ -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"
...
...
data/instance-b/rules/__init__.py
0 → 100644
View file @
9b70534a
#!/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/.
data/instance-b/rules/building_demo.py
0 → 100644
View file @
9b70534a
#!/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
))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment