Skip to content

Commit 2858a96

Browse files
author
maxim-lixakov
committed
[DOP-19992] - move log_url_template to server_settings
1 parent eb73767 commit 2858a96

File tree

21 files changed

+84
-81
lines changed

21 files changed

+84
-81
lines changed

.env.docker

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
TZ=UTC
22
ENV=LOCAL
33

4-
# Debug
4+
# Server Settngs
55
SYNCMASTER__SERVER__DEBUG=true
6+
SYNCMASTER__SERVER__LOG_URL_TEMPLATE=https://grafana.example.com?correlation_id={{ correlation_id }}&run_id={{ run.id }}
67

78
# Logging
89
SYNCMASTER__LOGGING__SETUP=True
@@ -11,9 +12,6 @@ SYNCMASTER__LOGGING__PRESET=colored
1112
# Encrypt / Decrypt credentials data
1213
SYNCMASTER__ENCRYPTION__CRYPTO_KEY=UBgPTioFrtH2unlC4XFDiGf5sYfzbdSf_VgiUSaQc94=
1314

14-
# Worker settings
15-
SYNCMASTER__WORKER__LOG_URL_TEMPLATE=https://grafana.example.com?correlation_id={{ correlation_id }}&run_id={{ run.id }}
16-
1715
# Scheduler settings
1816
SYNCMASTER__SCHEDULER__TRANSFER_FETCHING_TIMEOUT_SECONDS=200
1917

.env.local

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
export TZ=UTC
22
export ENV=LOCAL
33

4-
# Debug
4+
# Server Settngs
55
export SYNCMASTER__SERVER__DEBUG=true
6+
export SYNCMASTER__SERVER__LOG_URL_TEMPLATE="https://grafana.example.com?correlation_id={{ correlation_id }}&run_id={{ run.id }}"
67

78
# Logging
89
export SYNCMASTER__LOGGING__SETUP=True
910
export SYNCMASTER__LOGGING__PRESET=colored
1011

11-
# Worker settings
12-
export SYNCMASTER__WORKER__LOG_URL_TEMPLATE="https://grafana.example.com?correlation_id={{ correlation_id }}&run_id={{ run.id }}"
13-
1412
# Scheduler settings
1513
export SYNCMASTER__SCHEDULER__TRANSFER_FETCHING_TIMEOUT_SECONDS=200
1614

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ dev-server: db-start ##@Application Run development server (without docker)
113113
${POETRY} run python -m syncmaster.backend $(ARGS)
114114

115115
dev-worker: db-start broker-start ##@Application Run development broker (without docker)
116-
${POETRY} run python -m celery -A syncmaster.worker.config.celery worker --max-tasks-per-child=1 $(ARGS)
116+
${POETRY} run python -m celery -A syncmaster.worker.celery worker --max-tasks-per-child=1 $(ARGS)
117117

118118

119119

docker-compose.test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ services:
7979
context: .
8080
target: test
8181
command: --loglevel=info -Q test_queue
82-
entrypoint: [coverage, run, -m, celery, -A, tests.test_integration.celery_test, worker, --max-tasks-per-child=1]
82+
entrypoint: [coverage, run, -m, celery, -A, syncmaster.worker.celery, worker, --max-tasks-per-child=1]
8383
env_file: .env.docker
8484
environment:
8585
# CI runs tests in the worker container, so we need to turn off interaction with static files for it

docker/entrypoint_worker.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ set -e
55
# Required to start each Celery task in separated process, avoiding issues with global Spark session object
66

77
# exec is required to forward all signals to the main process
8-
exec python -m celery -A syncmaster.worker.config.celery worker --max-tasks-per-child=1 "$@"
8+
exec python -m celery -A syncmaster.worker.celery worker --max-tasks-per-child=1 "$@"
99

syncmaster/backend/api/v1/runs.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22
# SPDX-License-Identifier: Apache-2.0
33
import asyncio
44
from datetime import datetime
5+
from typing import Annotated
56

67
from asgi_correlation_id import correlation_id
78
from fastapi import APIRouter, Depends, Query
89
from jinja2 import Template
910
from kombu.exceptions import KombuError
1011

12+
from syncmaster.backend.dependencies import Stub
1113
from syncmaster.backend.services import UnitOfWork, get_user
14+
from syncmaster.backend.settings import ServerAppSettings as Settings
1215
from syncmaster.db.models import RunType, Status, User
1316
from syncmaster.db.utils import Permission
1417
from syncmaster.errors.registration import get_error_responses
@@ -21,8 +24,7 @@
2124
ReadRunSchema,
2225
RunPageSchema,
2326
)
24-
from syncmaster.worker.config import celery
25-
from syncmaster.worker.settings import get_worker_settings
27+
from syncmaster.worker import celery
2628

2729
router = APIRouter(tags=["Runs"], responses=get_error_responses())
2830

@@ -81,6 +83,7 @@ async def read_run(
8183
@router.post("/runs")
8284
async def start_run(
8385
create_run_data: CreateRunSchema,
86+
settings: Annotated[Settings, Depends(Stub(Settings))],
8487
unit_of_work: UnitOfWork = Depends(UnitOfWork),
8588
current_user: User = Depends(get_user(is_active=True)),
8689
) -> ReadRunSchema:
@@ -117,7 +120,7 @@ async def start_run(
117120
type=RunType.MANUAL,
118121
)
119122

120-
log_url = Template(get_worker_settings().worker.LOG_URL_TEMPLATE).render(
123+
log_url = Template(settings.server.log_url_template).render(
121124
run=run,
122125
correlation_id=correlation_id.get(),
123126
)

syncmaster/backend/settings/server/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ class ServerSettings(BaseModel):
3434
""",
3535
),
3636
)
37+
log_url_template: str = Field(
38+
"",
39+
description="URL template for logging",
40+
)
3741
request_id: RequestIDSettings = Field(
3842
default_factory=RequestIDSettings,
3943
)

syncmaster/scheduler/transfer_fetcher.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from sqlalchemy import select
44

55
from syncmaster.db.models import Transfer
6-
from syncmaster.scheduler.settings import SchedulerSettings as Settings
6+
from syncmaster.scheduler.settings import SchedulerAppSettings as Settings
77
from syncmaster.scheduler.utils import get_async_session
88

99

syncmaster/scheduler/transfer_job_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from syncmaster.scheduler.settings import SchedulerAppSettings as Settings
1313
from syncmaster.scheduler.utils import get_async_session
1414
from syncmaster.schemas.v1.connections.connection import ReadAuthDataSchema
15-
from syncmaster.worker.config import celery
15+
from syncmaster.worker import celery
1616

1717

1818
class TransferJobManager:

syncmaster/worker/__init__.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,24 @@
11
# SPDX-FileCopyrightText: 2023-2024 MTS PJSC
22
# SPDX-License-Identifier: Apache-2.0
3+
from celery import Celery
4+
5+
from syncmaster.worker.base import WorkerTask
6+
from syncmaster.worker.settings import WorkerAppSettings
7+
8+
9+
def create_celery_app(settings) -> Celery:
10+
app = Celery(
11+
__name__,
12+
broker=settings.broker.url,
13+
backend="db+" + settings.database.sync_url,
14+
task_cls=WorkerTask,
15+
imports=[
16+
"syncmaster.worker.transfer",
17+
],
18+
)
19+
return app
20+
21+
22+
# TODO: initialize celery app in __name__ == "__main__"
23+
# then initialize celery app in backend via dependency injection and initialize in scheduler
24+
celery = create_celery_app(WorkerAppSettings())

0 commit comments

Comments
 (0)