-
Notifications
You must be signed in to change notification settings - Fork 6
Test #187
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
Closed
Closed
Test #187
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
eac67ac
Add models for custom config validation
Nidhi091999 4302f1b
fix issues
Nidhi091999 98e7f46
fix lint issues
Nidhi091999 0e2b663
fix lint issues
Nidhi091999 e253ee3
fix lint issues
Nidhi091999 a2c3331
fix lint issues
Nidhi091999 55e47e3
fix pipeline
Nidhi091999 76aac22
Fix: Update app config to include custom section for validation
Nidhi091999 c27aa90
fix lint issues
Nidhi091999 04f9d38
checks
Nidhi091999 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,237 @@ | ||
"""Custom app config models.""" | ||
|
||
from typing import List, Optional | ||
import string | ||
from pydantic import BaseModel # pylint: disable=no-name-in-module | ||
from pro_tes.ga4gh.tes.models import Service as TesServiceInfo | ||
|
||
|
||
# pragma pylint: disable=too-few-public-methods | ||
|
||
|
||
class DB(BaseModel): | ||
"""DB config for post_task. | ||
|
||
Args: | ||
insert_attempts: Number of attempts to insert a new task in DB. | ||
|
||
Attributes: | ||
insert_attempts: Number of attempts to insert a new task in DB. | ||
""" | ||
|
||
insert_attempts: int = 10 | ||
|
||
|
||
class TaskID(BaseModel): | ||
"""Task ID config. | ||
|
||
Args: | ||
charset: Characters to use when generating task IDs. | ||
length: Length of the generated task ID. | ||
|
||
Attributes: | ||
charset: Characters to use when generating task IDs. | ||
length: Length of the generated task ID. | ||
""" | ||
|
||
charset: str = string.ascii_uppercase + string.digits | ||
length: int = 6 | ||
|
||
|
||
class Timeout(BaseModel): | ||
"""Timeout config. | ||
|
||
Args: | ||
post: Timeout for POST requests (None disables timeout). | ||
poll: Timeout for polling. | ||
job: Timeout for job execution (None disables timeout). | ||
|
||
Attributes: | ||
post: Timeout for POST requests (None disables timeout). | ||
poll: Timeout for polling. | ||
job: Timeout for job execution (None disables timeout). | ||
""" | ||
|
||
post: Optional[int] = None | ||
poll: int = 2 | ||
job: Optional[int] = None | ||
|
||
|
||
class Polling(BaseModel): | ||
"""Polling config. | ||
|
||
Args: | ||
wait: Wait time between polling attempts. | ||
attempts: Max polling attempts before failure. | ||
|
||
Attributes: | ||
wait: Wait time between polling attempts. | ||
attempts: Max polling attempts before failure. | ||
""" | ||
|
||
wait: int = 3 | ||
attempts: int = 100 | ||
|
||
|
||
class PostTask(BaseModel): | ||
"""Configuration for POST /task. | ||
|
||
Args: | ||
db: DB insert behavior. | ||
task_id: Task ID generation settings. | ||
timeout: Timeout settings. | ||
polling: Polling behavior. | ||
|
||
Attributes: | ||
db: DB insert behavior. | ||
task_id: Task ID generation settings. | ||
timeout: Timeout settings. | ||
polling: Polling behavior. | ||
""" | ||
|
||
db: DB = DB() | ||
task_id: TaskID = TaskID() | ||
timeout: Timeout = Timeout() | ||
polling: Polling = Polling() | ||
|
||
|
||
class ListTasks(BaseModel): | ||
"""Configuration for GET /tasks. | ||
|
||
Args: | ||
default_page_size: Default pagination size. | ||
|
||
Attributes: | ||
default_page_size: Default pagination size. | ||
""" | ||
|
||
default_page_size: int = 5 | ||
|
||
|
||
class Monitor(BaseModel): | ||
"""Celery monitor settings. | ||
|
||
Args: | ||
timeout: Timeout to wait for Celery monitoring. | ||
|
||
Attributes: | ||
timeout: Timeout to wait for Celery monitoring. | ||
""" | ||
|
||
timeout: float = 0.1 | ||
|
||
|
||
class Celery(BaseModel): | ||
"""Celery configuration. | ||
|
||
Args: | ||
monitor: Monitor settings. | ||
message_maxsize: Maximum allowed message size. | ||
|
||
Attributes: | ||
monitor: Monitor settings. | ||
message_maxsize: Maximum allowed message size. | ||
""" | ||
|
||
monitor: Monitor = Monitor() | ||
message_maxsize: int = 16777216 | ||
|
||
|
||
class Controllers(BaseModel): | ||
"""Controller configurations. | ||
|
||
Args: | ||
post_task: Settings for POST /task. | ||
list_tasks: Settings for GET /tasks. | ||
celery: Celery background task settings. | ||
|
||
Attributes: | ||
post_task: Settings for POST /task. | ||
list_tasks: Settings for GET /tasks. | ||
celery: Celery background task settings. | ||
""" | ||
|
||
post_task: PostTask = PostTask() | ||
list_tasks: ListTasks = ListTasks() | ||
celery: Celery = Celery() | ||
|
||
|
||
class Tes(BaseModel): | ||
"""TES backend configuration. | ||
|
||
Args: | ||
service_list: List of available TES services. | ||
|
||
Attributes: | ||
service_list: List of available TES services. | ||
""" | ||
|
||
service_list: List[str] = [ | ||
"https://csc-tesk-noauth.rahtiapp.fi", | ||
"https://funnel.cloud.e-infra.cz/", | ||
"https://tesk-eu.hypatia-comp.athenarc.gr", | ||
"https://tesk-na.cloud.e-infra.cz", | ||
"https://vm4816.kaj.pouta.csc.fi/", | ||
] | ||
|
||
|
||
class StoreLogs(BaseModel): | ||
"""Logging configuration. | ||
|
||
Args: | ||
execution_trace: Whether to store execution trace logs. | ||
|
||
Attributes: | ||
execution_trace: Whether to store execution trace logs. | ||
""" | ||
|
||
execution_trace: bool = True | ||
|
||
|
||
class Middlewares(BaseModel): | ||
"""Middleware configuration. | ||
|
||
Args: | ||
__root__: A list of middleware class paths. | ||
|
||
Attributes: | ||
__root__: A list of middleware class paths. | ||
""" | ||
|
||
__root__: List[List[str]] = [ | ||
[ | ||
( | ||
"pro_tes.plugins.middlewares.task_distribution.distance." | ||
"TaskDistributionDistance" | ||
), | ||
( | ||
"pro_tes.plugins.middlewares.task_distribution.random." | ||
"TaskDistributionRandom" | ||
), | ||
] | ||
] | ||
|
||
|
||
class CustomConfig(BaseModel): | ||
"""Custom app configuration. | ||
|
||
Args: | ||
controllers: All controller-related config. | ||
tes: TES service list and defaults. | ||
store_logs: Logging preferences. | ||
middlewares: Middleware class paths. | ||
service_info: Metadata about the service. | ||
|
||
Attributes: | ||
controllers: All controller-related config. | ||
tes: TES service list and defaults. | ||
store_logs: Logging preferences. | ||
middlewares: Middleware class paths. | ||
service_info: Metadata about the service. | ||
""" | ||
|
||
controllers: Controllers = Controllers() | ||
tes: Tes = Tes() | ||
storeLogs: StoreLogs = StoreLogs() | ||
middlewares: Middlewares = Middlewares() | ||
service_info: TesServiceInfo | ||
This file contains hidden or 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 hidden or 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 |
---|---|---|
|
@@ -62,7 +62,7 @@ def __init__(self) -> None: | |
self.db_client: Collection = ( | ||
self.foca_config.db.dbs["taskStore"].collections["tasks"].client | ||
) | ||
self.store_logs = self.foca_config.storeLogs["execution_trace"] | ||
self.store_logs = self.foca_config.custom.storeLogs["execution_trace"] | ||
|
||
def create_task( # pylint: disable=too-many-statements,too-many-branches | ||
self, **kwargs | ||
|
@@ -86,7 +86,7 @@ def create_task( # pylint: disable=too-many-statements,too-many-branches | |
# apply middlewares | ||
mw_handler = MiddlewareHandler() | ||
mw_handler.set_middlewares( | ||
paths=current_app.config.foca.middlewares # type: ignore | ||
paths=current_app.config.foca.custom.middlewares # type: ignore | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue (bug_risk): Passing Pydantic model instead of raw list to middleware handler Pass |
||
) | ||
logger.debug(f"Middlewares registered: {mw_handler.middlewares}") | ||
request_modified = mw_handler.apply_middlewares(request=request) | ||
|
@@ -268,8 +268,10 @@ def list_tasks(self, **kwargs) -> dict: | |
""" | ||
page_size = kwargs.get( | ||
"page_size", | ||
self.foca_config.controllers["list_tasks"]["default_page_size"], | ||
) | ||
self.foca_config.custom.controllers["list_tasks"][ | ||
"default_page_size" | ||
], | ||
) | ||
page_token = kwargs.get("page_token") | ||
filter_dict = {} | ||
|
||
|
@@ -427,7 +429,7 @@ def _write_doc_to_db( | |
Returns: | ||
Tuple of task id and worker id. | ||
""" | ||
controller_config = self.foca_config.controllers["post_task"] | ||
controller_config = self.foca_config.custom.controllers["post_task"] | ||
charset = controller_config["task_id"]["charset"] | ||
length = controller_config["task_id"]["length"] | ||
|
||
|
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (bug_risk): YAML key 'serviceInfo' does not match Pydantic field 'service_info'
Add
Field(..., alias='serviceInfo')
toservice_info
or rename it toserviceInfo
so the YAML key aligns and loads correctly.