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
Commits
1fffa276
Commit
1fffa276
authored
Jan 14, 2021
by
Felix Delattre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add very basic rule class
parent
01fd837a
Pipeline
#18408
passed with stage
in 1 minute and 7 seconds
Changes
4
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
14 additions
and
24 deletions
+14
-24
rabotnik/__init__.py
rabotnik/__init__.py
+2
-2
rabotnik/rabotnik.py
rabotnik/rabotnik.py
+2
-4
rabotnik/rule.py
rabotnik/rule.py
+9
-17
tests/test_rabotnik.py
tests/test_rabotnik.py
+1
-1
No files found.
rabotnik/__init__.py
View file @
1fffa276
...
...
@@ -16,8 +16,8 @@
# 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/.
from
.
task
import
Task
from
.
rule
import
Rule
from
.rabotnik
import
Rabotnik
__all__
=
[
"
Task"
,
"
Rabotnik"
]
__all__
=
[
"Rabotnik
"
,
"Rule
"
]
rabotnik/rabotnik.py
View file @
1fffa276
...
...
@@ -19,7 +19,6 @@
import
logging
from
.processor
import
Processor
from
.task
import
Task
from
.storage_factory
import
StorageFactory
logger
=
logging
.
getLogger
()
...
...
@@ -35,12 +34,11 @@ class Rabotnik:
:param storage_selector: selector which storage type to include
"""
# Set storage
to be used. Most likely a database.
self
.
storage
_selector
=
None
# Set storage
from an available backend
self
.
storage
=
None
if
storage_selector
:
storage_factory
=
StorageFactory
(
storage_selector
)
self
.
storage
=
storage_factory
.
get_storage
()
Task
.
_database
=
self
.
storage
# Set processor to be used. This is based on Celery.
self
.
processor
=
Processor
.
get_processor
(
name
)
rabotnik/
task
.py
→
rabotnik/
rule
.py
View file @
1fffa276
...
...
@@ -16,25 +16,17 @@
# 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
# noqa
import
logging
import
celery
from
celery.utils.log
import
get_task_logger
from
abc
import
ABC
,
abstractmethod
logger
=
logging
.
getLogger
()
logger
=
get_task_logger
(
__name__
)
class
Rule
(
ABC
):
"""Basic rule object"""
class
Task
(
celery
.
Task
):
"""Tasks that use this class as their *base* will have access
to the *database* instance wthin the task.
"""
_database
=
None
@
property
def
database
(
self
):
if
self
.
_database
is
None
:
raise
Exception
(
"No database set"
)
return
self
.
_database
@
abstractmethod
def
evaluate
(
self
,
id
:
int
):
"""Main function to execute a rules"""
...
tests/test_rabotnik.py
View file @
1fffa276
...
...
@@ -21,4 +21,4 @@ from rabotnik.rabotnik import Rabotnik
def
test_rabotnik_init
():
rabotnik
=
Rabotnik
(
"test"
)
assert
rabotnik
.
storage
_selector
is
None
assert
rabotnik
.
storage
is
None
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