move snake config read functions into battlesnake template and use TemplateSnake as default Version of Snakes
Build and Push Docker Container / build-and-push (push) Failing after 13m9s
Build and Push Docker Container / build-and-push (push) Failing after 13m9s
This commit is contained in:
+3
-33
@@ -1,6 +1,5 @@
|
||||
from quart_common.web.logger import build_logger, await_log
|
||||
from quart_common.web.env import env_bool, env_int
|
||||
from server.Files import read_file
|
||||
|
||||
from server.game_state_store import GameStateStoreBuilder
|
||||
from snakes import SnakeBuilder
|
||||
@@ -14,8 +13,7 @@ from server.metrics import (
|
||||
MetricsCollector,
|
||||
)
|
||||
|
||||
import asyncio, signal, logging, json, os, re, time
|
||||
from typing import cast
|
||||
import asyncio, signal, logging, os, re, time
|
||||
from quart import Quart
|
||||
|
||||
from server.blueprints import (
|
||||
@@ -32,15 +30,6 @@ from server.services import (
|
||||
)
|
||||
|
||||
class Server:
|
||||
default_snake_config = {
|
||||
'apiversion': '1',
|
||||
'author': '',
|
||||
'color': '#888888',
|
||||
'head': 'default',
|
||||
'tail': 'default',
|
||||
'version': '1.0.0',
|
||||
}
|
||||
|
||||
def __init__(self, data_path:str, snake_type:str, storage_type:str, debug:bool=False, check_tls_security:bool=False, game_state_backend:str='memory', game_state_redis_url:str='redis://localhost:6379/0', game_state_ttl_sec:int=900, game_state_local_cache:bool=True, metrics_backend:str='memory', metrics_redis_url:str='redis://localhost:6379/0', metrics_ttl_sec:int|None=None, gameplay_db_enabled:bool=True, gameplay_db_path:str|None=None, gameplay_db_busy_timeout_ms:int=5000):
|
||||
self.debug = debug
|
||||
self.snake_type = snake_type
|
||||
@@ -97,6 +86,7 @@ class Server:
|
||||
|
||||
self.logger = build_logger('Battlesnake', debug_env_var='DEBUG_SERVER')
|
||||
self.snake_version = self._get_snake_version()
|
||||
|
||||
self.gameplay_database = None
|
||||
if gameplay_db_enabled:
|
||||
db_path = gameplay_db_path or os.path.join(data_path, 'data', 'database', 'gameplay.sqlite3')
|
||||
@@ -190,30 +180,10 @@ class Server:
|
||||
except Exception:
|
||||
continue
|
||||
|
||||
async def _read_json_config_or_create(self) -> dict[str, str]:
|
||||
snake_config = cast(dict[str, str]|None, await read_file(self.config_file, json.load))
|
||||
if not snake_config:
|
||||
return await self._override_snake_config_with_environment_variables(self.default_snake_config)
|
||||
return await self._override_snake_config_with_environment_variables(snake_config)
|
||||
|
||||
async def _override_snake_config_with_environment_variables(self, config:dict[str, str]) -> dict[str, str]:
|
||||
config['version'] = self.snake_version
|
||||
|
||||
for key in ('author', 'color', 'head', 'tail'):
|
||||
value = os.environ.get(f'SNAKE_{key.upper()}')
|
||||
if value is not None:
|
||||
config[key] = value
|
||||
|
||||
version_override = os.environ.get('SNAKE_VERSION')
|
||||
if version_override is not None:
|
||||
config['version'] = version_override
|
||||
|
||||
return config
|
||||
|
||||
def _get_snake_version(self) -> str:
|
||||
configured_version = SnakeBuilder.get_version(self.snake_type)
|
||||
if configured_version is None:
|
||||
return self.default_snake_config['version']
|
||||
return str(SnakeBuilder.get_version('TemplateSnake'))
|
||||
return str(configured_version)
|
||||
|
||||
def _get_stale_game_timeout_sec(self) -> int:
|
||||
|
||||
Reference in New Issue
Block a user