mirror of
https://github.com/nexus-stc/hyperboria
synced 2024-11-23 03:26:50 +01:00
- fix(bot): Rework disabled IDM logic
- feat(nexus): Update aiogrpcclient - feat(bot): Added option to disable IDM - feat(nexus): Detach postgres from Hub 2 internal commit(s) GitOrigin-RevId: bf55fbc64136be36fab362c5f48b7c2b78f0d08e
This commit is contained in:
parent
ff50edbf36
commit
f8313f38b9
11
WORKSPACE
11
WORKSPACE
@ -229,6 +229,17 @@ container_repositories()
|
||||
|
||||
load("@io_bazel_rules_docker//repositories:deps.bzl", container_deps = "deps")
|
||||
|
||||
# ToDo: temorary fix as registry was broken at 24.04.2021
|
||||
load("@bazel_gazelle//:deps.bzl", "go_repository")
|
||||
|
||||
go_repository(
|
||||
name = "com_github_google_go_containerregistry",
|
||||
importpath = "github.com/google/go-containerregistry",
|
||||
strip_prefix = "google-go-containerregistry-8a28419",
|
||||
type = "tar.gz",
|
||||
urls = ["https://api.github.com/repos/google/go-containerregistry/tarball/8a2841911ffee4f6892ca0083e89752fb46c48dd"], # v0.1.4
|
||||
)
|
||||
|
||||
container_deps()
|
||||
|
||||
load("@io_bazel_rules_docker//repositories:py_repositories.bzl", "py_deps")
|
||||
|
@ -21,15 +21,18 @@ class TelegramApplication(AioRootThing):
|
||||
)
|
||||
|
||||
self.hub_client = HubGrpcClient(base_url=self.config['hub']['url'])
|
||||
self.idm_client = IdmApiGrpcClient(base_url=self.config['idm']['url'])
|
||||
self.starts.append(self.hub_client)
|
||||
self.idm_client = None
|
||||
if self.config['idm']['enabled']:
|
||||
self.idm_client = IdmApiGrpcClient(base_url=self.config['idm']['url'])
|
||||
self.starts.append(self.idm_client)
|
||||
self.meta_api_client = MetaApiGrpcClient(base_url=self.config['meta_api']['url'])
|
||||
self.starts.append(self.meta_api_client)
|
||||
|
||||
self.promotioner = Promotioner(promotions=self.config['promotions'])
|
||||
self.user_manager = UserManager()
|
||||
self._handlers = []
|
||||
|
||||
self.starts.extend([self.hub_client, self.idm_client, self.meta_api_client])
|
||||
|
||||
def set_handlers(self, telegram_client):
|
||||
for handler in self.config['telegram']['handlers']:
|
||||
import_object(handler)(self).register_for(telegram_client)
|
||||
|
@ -44,6 +44,7 @@ application:
|
||||
hub:
|
||||
url:
|
||||
idm:
|
||||
enabled: false
|
||||
url:
|
||||
log_path: '/var/log/nexus-bot'
|
||||
meta_api:
|
||||
|
@ -185,6 +185,15 @@ class BaseHandler(ABC):
|
||||
request_context.error_log(e)
|
||||
|
||||
async def _put_chat(self, event: events.ChatAction, request_id: str):
|
||||
event_chat = await event.get_chat()
|
||||
username = get_username(event, event_chat)
|
||||
language = get_language(event, event_chat)
|
||||
if not self.application.idm_client:
|
||||
return ChatPb(
|
||||
chat_id=event.chat_id,
|
||||
username=username,
|
||||
language=language,
|
||||
)
|
||||
try:
|
||||
chat = await self.application.idm_client.get_chat(
|
||||
chat_id=event.chat_id,
|
||||
@ -196,9 +205,6 @@ class BaseHandler(ABC):
|
||||
raise
|
||||
if self.application.config['application']['is_read_only_mode']:
|
||||
raise ReadOnlyModeError()
|
||||
event_chat = await event.get_chat()
|
||||
username = get_username(event, event_chat)
|
||||
language = get_language(event, event_chat)
|
||||
if language not in {'en', 'ru'}:
|
||||
language = 'en'
|
||||
chat = await self.application.idm_client.create_chat(
|
||||
|
@ -3,7 +3,7 @@
|
||||
application:
|
||||
debug: true
|
||||
# Enable special Postgres `sharience` table to retrieve user-sent files
|
||||
is_sharience_enabled: true
|
||||
is_sharience_enabled: false
|
||||
# URL to the picture shown while maintenance
|
||||
maintenance_picture_url:
|
||||
# Used in logging
|
||||
@ -12,6 +12,7 @@ application:
|
||||
should_store_hashes: true
|
||||
database:
|
||||
database: nexus
|
||||
enabled: false
|
||||
host:
|
||||
password:
|
||||
username:
|
||||
|
@ -15,15 +15,20 @@ class GrpcServer(AioGrpcServer):
|
||||
def __init__(self, config: Configurator):
|
||||
self.log_config(config)
|
||||
super().__init__(address=config['grpc']['address'], port=config['grpc']['port'])
|
||||
self.pool_holder = AioPostgresPoolHolder(
|
||||
dsn=f'dbname={config["database"]["database"]} '
|
||||
f'user={config["database"]["username"]} '
|
||||
f'password={config["database"]["password"]} '
|
||||
f'host={config["database"]["host"]}',
|
||||
timeout=30,
|
||||
pool_recycle=60,
|
||||
maxsize=4,
|
||||
)
|
||||
|
||||
self.pool_holder = None
|
||||
if config['database']['enabled']:
|
||||
self.pool_holder = AioPostgresPoolHolder(
|
||||
dsn=f'dbname={config["database"]["database"]} '
|
||||
f'user={config["database"]["username"]} '
|
||||
f'password={config["database"]["password"]} '
|
||||
f'host={config["database"]["host"]}',
|
||||
timeout=30,
|
||||
pool_recycle=60,
|
||||
maxsize=4,
|
||||
)
|
||||
self.waits.append(self.pool_holder)
|
||||
|
||||
self.telegram_client = BaseTelegramClient(
|
||||
app_id=config['telegram']['app_id'],
|
||||
app_hash=config['telegram']['app_hash'],
|
||||
@ -32,6 +37,7 @@ class GrpcServer(AioGrpcServer):
|
||||
mtproxy=config['telegram'].get('mtproxy'),
|
||||
)
|
||||
self.starts.append(self.telegram_client)
|
||||
|
||||
self.delivery_service = DeliveryService(
|
||||
server=self.server,
|
||||
service_name=config['application']['service_name'],
|
||||
@ -46,6 +52,7 @@ class GrpcServer(AioGrpcServer):
|
||||
telegram_client=self.telegram_client,
|
||||
)
|
||||
self.starts.append(self.delivery_service)
|
||||
|
||||
if config['grobid']['enabled']:
|
||||
self.submitter_service = SubmitterService(
|
||||
server=self.server,
|
||||
@ -57,7 +64,6 @@ class GrpcServer(AioGrpcServer):
|
||||
telegram_client=self.telegram_client,
|
||||
)
|
||||
self.starts.append(self.submitter_service)
|
||||
self.waits.append(self.pool_holder)
|
||||
|
||||
|
||||
def main():
|
||||
|
@ -324,6 +324,8 @@ class DeliveryService(DeliveryServicer, BaseHubService):
|
||||
should_use_telegram_file_id: bool,
|
||||
telegram_client: BaseTelegramClient,
|
||||
):
|
||||
if is_sharience_enabled and not pool_holder:
|
||||
raise ValueError('Sharience can be used only with enabled database')
|
||||
super().__init__(
|
||||
service_name=service_name,
|
||||
bot_external_name=bot_external_name,
|
||||
|
@ -4,7 +4,7 @@ aiobaseclient==0.2.4
|
||||
aiochclient==2.0.0
|
||||
aiocrossref==0.2.1
|
||||
aiogrobid==0.1.2
|
||||
aiogrpcclient==0.1.1
|
||||
aiogrpcclient==0.1.2
|
||||
aiodns==2.0.0
|
||||
aioftp==0.18.1
|
||||
aiohttp[speedups]==3.7.4.post0
|
||||
|
Loading…
Reference in New Issue
Block a user