Commit 1fffa276 authored by Felix Delattre's avatar Felix Delattre

Add very basic rule class

parent 01fd837a
Pipeline #18408 passed with stage
in 1 minute and 7 seconds
......@@ -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"]
......@@ -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)
......@@ -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"""
...
......@@ -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
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