-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from somakeit/11-central-db
11 central db
- Loading branch information
Showing
21 changed files
with
838 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,9 @@ | |
"tzlocal": { | ||
"level": "WARNING", | ||
"propagate": false | ||
}, | ||
"pymongo": { | ||
"level": "WARNING" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import functools | ||
import inspect | ||
from pathlib import Path | ||
|
||
from injectable import inject | ||
from mogo import Model, Field, connect | ||
|
||
from smib.slack.plugin import PluginManager | ||
from smib.common.utils import get_module_file | ||
from smib.common.config import MONGO_DB_URL, MONGO_DB_CONNECT_TIMEOUT_SECONDS | ||
|
||
|
||
def get_current_plugin_id() -> str: | ||
plugin_manager: PluginManager = inject("PluginManager") | ||
plugin_name = plugin_manager.get_plugin_from_file(get_module_file(2)).id | ||
return plugin_name | ||
|
||
|
||
def database(database_name: str = None): | ||
def decorator(func): | ||
@functools.wraps(func) | ||
def wrapper(*args, **kwargs): | ||
db_name = database_name | ||
|
||
# If no database_name parameter name passed in, get current plugin id and use that | ||
if db_name is None: | ||
plugin_file = Path(inspect.getfile(func)) | ||
plugin_manager: PluginManager = inject("PluginManager") | ||
db_name = plugin_manager.get_plugin_from_file(plugin_file).id | ||
|
||
inject("logger").debug(f"Database name: {db_name}") | ||
|
||
# Connect to DB and close it afterward | ||
with connect(db_name, uri=MONGO_DB_URL, timeoutMs=1000*MONGO_DB_CONNECT_TIMEOUT_SECONDS): | ||
return func(*args, **kwargs) | ||
|
||
return wrapper | ||
|
||
return decorator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
from injectable import inject | ||
from smib.common.logging_.setup import plugin_logger_factory | ||
|
||
|
||
|
||
def inject_logger_to_slack_context(context, next): | ||
context['logger'] = inject("plugin_logger", lazy=True) | ||
next() | ||
next() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from smib.slack.db import Model, Field | ||
|
||
|
||
class Space(Model): | ||
open: bool = Field[bool](default=None) | ||
|
||
@classmethod | ||
def single(cls): | ||
return cls.find_one() or cls() | ||
|
||
def set_open(self): | ||
self.open = True | ||
self.save() | ||
|
||
def set_closed(self): | ||
self.open = False | ||
self.save() |
Oops, something went wrong.