##// END OF EJS Templates
fix(mercurial): actually use assert_path instead of always initializing repo object....
fix(mercurial): actually use assert_path instead of always initializing repo object. This makes it consistent with how things work on git and svn sides

File last commit:

r5459:7f730862 default
r5581:68a5b57b default
Show More
base.py
89 lines | 3.3 KiB | text/x-python | PythonLexer
feat(ssh-wrapper-speedup): major rewrite of code to address imports problem with ssh-wrapper-v2...
r5325 # Copyright (C) 2010-2023 RhodeCode GmbH
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License, version 3
# (only), as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# 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/>.
#
# This program is dual-licensed. If you wish to learn more about the
# RhodeCode Enterprise Edition, including its added features, Support services,
# and proprietary license terms, please see https://rhodecode.com/licenses/
fix(svn): svn events fixes and change the way how we handle the events
r5459
feat(ssh-wrapper-speedup): major rewrite of code to address imports problem with ssh-wrapper-v2...
r5325 import os
import time
import logging
from rhodecode.lib.config_utils import get_config
fix(svn): svn events fixes and change the way how we handle the events
r5459
from rhodecode.lib.svn_txn_utils import get_txn_id_from_store
feat(ssh-wrapper-speedup): major rewrite of code to address imports problem with ssh-wrapper-v2...
r5325
log = logging.getLogger(__name__)
class BaseHooksCallbackDaemon:
"""
Basic context manager for actions that don't require some extra
"""
def __init__(self):
pass
def __enter__(self):
log.debug('Running `%s` callback daemon', self.__class__.__name__)
return self
def __exit__(self, exc_type, exc_val, exc_tb):
log.debug('Exiting `%s` callback daemon', self.__class__.__name__)
class HooksModuleCallbackDaemon(BaseHooksCallbackDaemon):
def __init__(self, module):
super().__init__()
self.hooks_module = module
fix(svn): svn events fixes and change the way how we handle the events
r5459 def __repr__(self):
return f'HooksModuleCallbackDaemon(hooks_module={self.hooks_module})'
feat(ssh-wrapper-speedup): major rewrite of code to address imports problem with ssh-wrapper-v2...
r5325
def prepare_callback_daemon(extras, protocol, host, txn_id=None):
fix(svn): svn events fixes and change the way how we handle the events
r5459
feat(ssh-wrapper-speedup): major rewrite of code to address imports problem with ssh-wrapper-v2...
r5325 match protocol:
case 'http':
from rhodecode.lib.hook_daemon.http_hooks_deamon import HttpHooksCallbackDaemon
fix(svn): svn events fixes and change the way how we handle the events
r5459 port = 0
if txn_id:
# read txn-id to re-use the PORT for callback daemon
repo_path = os.path.join(extras['repo_store'], extras['repository'])
txn_details = get_txn_id_from_store(repo_path, txn_id)
port = txn_details.get('port', 0)
feat(ssh-wrapper-speedup): major rewrite of code to address imports problem with ssh-wrapper-v2...
r5325 callback_daemon = HttpHooksCallbackDaemon(
txn_id=txn_id, host=host, port=port)
case 'celery':
from rhodecode.lib.hook_daemon.celery_hooks_deamon import CeleryHooksCallbackDaemon
callback_daemon = CeleryHooksCallbackDaemon(get_config(extras['config']))
case 'local':
from rhodecode.lib.hook_daemon.hook_module import Hooks
callback_daemon = HooksModuleCallbackDaemon(Hooks.__module__)
case _:
log.error('Unsupported callback daemon protocol "%s"', protocol)
raise Exception('Unsupported callback daemon protocol.')
extras['hooks_uri'] = getattr(callback_daemon, 'hooks_uri', '')
extras['task_queue'] = getattr(callback_daemon, 'task_queue', '')
extras['task_backend'] = getattr(callback_daemon, 'task_backend', '')
extras['hooks_protocol'] = protocol
extras['time'] = time.time()
# register txn_id
extras['txn_id'] = txn_id
log.debug('Prepared a callback daemon: %s',
callback_daemon.__class__.__name__)
return callback_daemon, extras