forked from platypush/platypush
Fabio Manganiello
86edd70d93
- The `declarative_base` instance should be shared - Database `session_locks` should be stored at module, not instance level - Better isolation of scoped sessions - Enclapsulated `get_session` method in `UserManager`
38 lines
853 B
Python
38 lines
853 B
Python
import warnings
|
|
from typing import Collection, Optional
|
|
|
|
from ._base import Entity, get_entities_registry
|
|
from ._engine import EntitiesEngine
|
|
from ._registry import manages, register_entity_plugin, get_plugin_entity_registry
|
|
|
|
_engine: Optional[EntitiesEngine] = None
|
|
|
|
|
|
def init_entities_engine() -> EntitiesEngine:
|
|
from ._base import init_entities_db
|
|
|
|
global _engine
|
|
init_entities_db()
|
|
_engine = EntitiesEngine()
|
|
_engine.start()
|
|
return _engine
|
|
|
|
|
|
def publish_entities(entities: Collection[Entity]):
|
|
if not _engine:
|
|
warnings.warn('No entities engine registered')
|
|
return
|
|
|
|
_engine.post(*entities)
|
|
|
|
|
|
__all__ = (
|
|
'Entity',
|
|
'EntitiesEngine',
|
|
'init_entities_engine',
|
|
'publish_entities',
|
|
'register_entity_plugin',
|
|
'get_plugin_entity_registry',
|
|
'get_entities_registry',
|
|
'manages',
|
|
)
|