You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.1 KiB
Python
40 lines
1.1 KiB
Python
from __future__ import annotations
|
|
|
|
from iti.storage import StorageManager
|
|
from iti.tasks import task_registry
|
|
|
|
from .base import ExchangeTaskContext
|
|
|
|
|
|
def register_exchange_task(
|
|
*,
|
|
name: str,
|
|
handler,
|
|
schedule: str | None = None,
|
|
description: str | None = None,
|
|
):
|
|
return task_registry.register(
|
|
name=name,
|
|
handler=handler,
|
|
schedule=schedule,
|
|
description=description,
|
|
)
|
|
|
|
|
|
def wrap_exchange_task(handler):
|
|
def runner(context: ExchangeTaskContext):
|
|
return handler(context)
|
|
|
|
return runner
|
|
|
|
|
|
def get_exchange_storage(app):
|
|
base_config = dict(getattr(app.state.config, "file_storage", {}) or {})
|
|
exchange_config = dict(getattr(app.state.config, "exchange_storage", {}) or {})
|
|
base_config.update(exchange_config)
|
|
default_storage = getattr(app.state.config, "exchange_default_storage", None)
|
|
if default_storage and "DEFAULT_STORAGE_TYPE" not in exchange_config:
|
|
base_config["DEFAULT_STORAGE_TYPE"] = default_storage
|
|
base_dir = getattr(app.state.config, "base_dir", None)
|
|
return StorageManager.get_storage(config=base_config, base_dir=base_dir)
|