Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Err #169

Merged
merged 2 commits into from
Jan 10, 2024
Merged

Err #169

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.6.10] - 2023-01-10
### Added
- Services: creation_error_message

## [1.6.9] - 2023-01-09
### Updated
- fix openai patches by patch_openai_proxies
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# OctoBot-Services [1.6.9](https://github.com/Drakkar-Software/OctoBot-Services/tree/master/docs/CHANGELOG.md)
# OctoBot-Services [1.6.10](https://github.com/Drakkar-Software/OctoBot-Services/tree/master/docs/CHANGELOG.md)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/31a1caa6e5384d80bf890dba5c9b5e4b)](https://app.codacy.com/gh/Drakkar-Software/OctoBot-Services?utm_source=github.com&utm_medium=referral&utm_content=Drakkar-Software/OctoBot-Services&utm_campaign=Badge_Grade_Dashboard)
[![PyPI](https://img.shields.io/pypi/v/OctoBot-Services.svg)](https://pypi.python.org/pypi/OctoBot-Services/)
[![Github-Action-CI](https://github.com/Drakkar-Software/OctoBot-Services/workflows/OctoBot-Services-CI/badge.svg)](https://github.com/Drakkar-Software/OctoBot-Services/actions)
Expand Down
2 changes: 1 addition & 1 deletion octobot_services/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
# License along with this library.

PROJECT_NAME = "OctoBot-Services"
VERSION = "1.6.9" # major.minor.revision
VERSION = "1.6.10" # major.minor.revision
8 changes: 6 additions & 2 deletions octobot_services/abstract_service_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,18 @@ async def _initialize_impl(self, backtesting_enabled, edited_config) -> bool:

async def _create_or_get_service_instance(self, service, backtesting_enabled, edited_config):
service_factory = services.ServiceFactory(self.config)
if await service_factory.create_or_get_service(service, backtesting_enabled, edited_config):
created, error_message = await service_factory.create_or_get_service(
service, backtesting_enabled, edited_config
)
if created:
return True
else:
log_func = self.get_logger().debug
# log error when the issue is not related to configuration
if service.instance().has_required_configuration():
log_func = self.get_logger().warning
log_func(f"Impossible to start {self.get_name()}: required service {service.get_name()} is not available.")
log_func(f"Impossible to start {self.get_name()}: required service {service.get_name()} "
f"is not available ({error_message}).")
return False

def has_required_services_configuration(self):
Expand Down
7 changes: 4 additions & 3 deletions octobot_services/api/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,21 @@ def get_available_services() -> list:
async def get_service(service_class, is_backtesting, config=None):
# prevent concurrent access when creating a service
async with _service_async_lock(service_class):
if await create_service_factory(
created, error_message = await create_service_factory(
interfaces.get_startup_config(dict_only=True) if config is None else config
).create_or_get_service(
service_class,
is_backtesting,
interfaces.get_edited_config(dict_only=True) if config is None else config
):
)
if created:
service = service_class.instance()
if is_backtesting and not service.BACKTESTING_ENABLED:
raise errors.UnavailableInBacktestingError(
f"{service_class.__name__} service is not available in backtesting"
)
return service
raise errors.CreationError(f"{service_class.__name__} service has not been properly created")
raise errors.CreationError(f"{service_class.__name__} service is not initialized: {error_message}")


def create_service_factory(config) -> services.ServiceFactory:
Expand Down
1 change: 1 addition & 0 deletions octobot_services/services/abstract_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def __init__(self):
self.logger = None
self.config = None
self.edited_config = None
self.creation_error_message = None
self._created = True
self._healthy = False
self._has_been_created = False
Expand Down
14 changes: 9 additions & 5 deletions octobot_services/services/service_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,20 @@ def __init__(self, config):
def get_available_services() -> list:
return [service_class for service_class in services.AbstractService.__subclasses__()]

async def create_or_get_service(self, service_class, backtesting_enabled, edited_config) -> bool:
async def create_or_get_service(self, service_class, backtesting_enabled, edited_config) -> (bool, str):
"""
create_or_get_service will create a service instance if it doesn't exist, check the existing one otherwise
:param service_class: the class of the service to create
:return: True if the created service is working properly, False otherwise
"""
service_instance = service_class.instance()
if service_instance.get_has_been_created():
return service_instance.is_healthy()
return service_instance.is_healthy(), service_instance.creation_error_message
else:
return await self._create_service(service_instance, backtesting_enabled, edited_config)
return (
await self._create_service(service_instance, backtesting_enabled, edited_config),
service_instance.creation_error_message
)

async def _create_service(self, service, backtesting_enabled, edited_config) -> bool:
service.is_backtesting_enabled = backtesting_enabled
Expand All @@ -51,8 +54,9 @@ async def _create_service(self, service, backtesting_enabled, edited_config) ->
return await self._perform_checkup(service)
else:
if service.get_should_warn():
self.logger.info(f"{service.get_name()} can't be initialized: configuration "
f"is missing, wrong or incomplete. This is normal if you did not configure it yet.")
service.creation_error_message = \
"Configuration is missing, wrong or incomplete. This is normal if you did not configure it yet."
self.logger.info(f"{service.get_name()} can't be initialized: {service.creation_error_message}")
return False

async def _perform_checkup(self, service) -> bool:
Expand Down