Skip to content

Commit 77d3109

Browse files
author
maxim-lixakov
committed
[DOP-19992] - split settings to different classes
1 parent 9ede4d5 commit 77d3109

File tree

15 files changed

+85
-29
lines changed

15 files changed

+85
-29
lines changed

.env.docker

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,19 @@ SYNCMASTER__SERVER__DEBUG=true
77
# Logging
88
SYNCMASTER__LOGGING__SETUP=True
99
SYNCMASTER__LOGGING__PRESET=colored
10-
SYNCMASTER__LOG_URL_TEMPLATE=https://grafana.example.com?correlation_id={{ correlation_id }}&run_id={{ run.id }}
11-
12-
# Session
13-
SYNCMASTER__SERVER__SESSION__SECRET_KEY=session_secret_key
1410

1511
# Encrypt / Decrypt credentials data
1612
SYNCMASTER__CRYPTO_KEY=UBgPTioFrtH2unlC4XFDiGf5sYfzbdSf_VgiUSaQc94=
1713

14+
# Worker settings
15+
SYNCMASTER__WORKER__LOG_URL_TEMPLATE=https://grafana.example.com?correlation_id={{ correlation_id }}&run_id={{ run.id }}
16+
17+
# Scheduler settings
18+
SYNCMASTER__SCHEDULER__TRANSFER_FETCHING_TIMEOUT_SECONDS=200
19+
20+
# Session
21+
SYNCMASTER__SERVER__SESSION__SECRET_KEY=session_secret_key
22+
1823
# Postgres
1924
SYNCMASTER__DATABASE__URL=postgresql+asyncpg://syncmaster:changeme@db:5432/syncmaster
2025

@@ -26,6 +31,7 @@ SYNCMASTER__AUTH__CLIENT_ID=manually_created
2631
SYNCMASTER__AUTH__CLIENT_SECRET=generated_by_keycloak
2732
SYNCMASTER__AUTH__REDIRECT_URI=http://localhost:8000/v1/auth/callback
2833
SYNCMASTER__AUTH__SCOPE=email
34+
SYNCMASTER__AUTH__VERIFY_SSL=False
2935
SYNCMASTER__AUTH__PROVIDER=syncmaster.backend.providers.auth.keycloak_provider.KeycloakAuthProvider
3036

3137
# Dummy Auth

.env.local

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ export SYNCMASTER__SERVER__DEBUG=true
77
# Logging
88
export SYNCMASTER__LOGGING__SETUP=True
99
export SYNCMASTER__LOGGING__PRESET=colored
10-
export SYNCMASTER__LOG_URL_TEMPLATE="https://grafana.example.com?correlation_id={{ correlation_id }}&run_id={{ run.id }}"
10+
11+
# Worker settings
12+
export SYNCMASTER__WORKER__LOG_URL_TEMPLATE="https://grafana.example.com?correlation_id={{ correlation_id }}&run_id={{ run.id }}"
13+
14+
# Scheduler settings
15+
export SYNCMASTER__SCHEDULER__TRANSFER_FETCHING_TIMEOUT_SECONDS=200
1116

1217
# Session
1318
export SYNCMASTER__SERVER__SESSION__SECRET_KEY=session_secret_key
@@ -25,6 +30,7 @@ export SYNCMASTER__AUTH__CLIENT_ID=manually_created
2530
export SYNCMASTER__AUTH__CLIENT_SECRET=generated_by_keycloak
2631
export SYNCMASTER__AUTH__REDIRECT_URI=http://localhost:8000/auth/callback
2732
export SYNCMASTER__AUTH__SCOPE=email
33+
export SYNCMASTER__AUTH__VERIFY_SSL=False
2834
export SYNCMASTER__AUTH__PROVIDER=syncmaster.backend.providers.auth.keycloak_provider.KeycloakAuthProvider
2935

3036
# Dummy Auth

.readthedocs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ build:
1717
- VIRTUAL_ENV=$READTHEDOCS_VIRTUALENV_PATH python -m poetry install --no-root --all-extras --with docs --without dev,test
1818
- VIRTUAL_ENV=$READTHEDOCS_VIRTUALENV_PATH python -m poetry show -v
1919
- python -m pip list -v
20-
- SYNCMASTER__DATABASE__URL=postgresql+psycopg://fake:[email protected]:5432/fake SYNCMASTER__SERVER__SESSION__SECRET_KEY=session_secret_key SYNCMASTER__BROKER__URL=amqp://fake:faket@fake:5672/ SYNCMASTER__CRYPTO_KEY=crypto_key SYNCMASTER__AUTH__ACCESS_TOKEN__SECRET_KEY=fakepython python -m syncmaster.backend.export_openapi_schema docs/_static/openapi.json
20+
- SYNCMASTER__DATABASE__URL=postgresql+psycopg://fake:[email protected]:5432/fake SYNCMASTER__SERVER__SESSION__SECRET_KEY=session_secret_key SYNCMASTER__BROKER__URL=amqp://fake:faket@fake:5672/ SYNCMASTER__CRYPTO_KEY=crypto_key SYNCMASTER__AUTH__ACCESS_TOKEN__SECRET_KEY=fakepython python -m syncmaster.backend.export_openapi_schema docs/_static/openapi.json
2121

2222
sphinx:
2323
configuration: docs/conf.py

docker/Dockerfile.worker

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ COPY ./syncmaster/ /app/syncmaster/
3939

4040
FROM base as test
4141

42-
ENV SYNCMASTER__CREATE_SPARK_SESSION_FUNCTION=tests.spark.get_worker_spark_session
42+
ENV SYNCMASTER__WORKER__CREATE_SPARK_SESSION_FUNCTION=tests.spark.get_worker_spark_session
4343

4444
# CI runs tests in the worker container, so we need backend dependencies too
4545
RUN poetry install --no-root --all-extras --with test --without docs,dev

syncmaster/backend/api/v1/runs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,5 +167,5 @@ async def stop_run(
167167

168168
async with unit_of_work:
169169
run = await unit_of_work.run.stop(run_id=run_id)
170-
# TODO: add immdiate stop transfer after stop Run
170+
# TODO: add immediate stop transfer after stop Run
171171
return ReadRunSchema.from_orm(run)

syncmaster/scheduler/__main__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import asyncio
44
import logging
55

6-
from syncmaster.backend.settings import BackendSettings as Settings
6+
from syncmaster.scheduler.settings import SchedulerSettings as Settings
77
from syncmaster.scheduler.transfer_fetcher import TransferFetcher
88
from syncmaster.scheduler.transfer_job_manager import TransferJobManager
99

@@ -30,7 +30,7 @@ async def main():
3030
transfer_fetcher.last_updated_at = max(t.updated_at for t in transfers)
3131
logger.info("Scheduler state has been updated. Last updated at: %s", transfer_fetcher.last_updated_at)
3232

33-
await asyncio.sleep(settings.SCHEDULER_TRANSFER_FETCHING_TIMEOUT)
33+
await asyncio.sleep(settings.TRANSFER_FETCHING_TIMEOUT_SECONDS)
3434

3535

3636
if __name__ == "__main__":
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# SPDX-FileCopyrightText: 2023-2024 MTS PJSC
2+
# SPDX-License-Identifier: Apache-2.0
3+
from pydantic import Field
4+
5+
from syncmaster.settings import SyncmasterSettings
6+
7+
8+
class SchedulerSettings(SyncmasterSettings):
9+
"""Celery scheduler settings.
10+
11+
Examples
12+
--------
13+
14+
.. code-block:: bash
15+
16+
SYNCMASTER__SCHEDULER__TRANSFER_FETCHING_TIMEOUT=200
17+
"""
18+
19+
TRANSFER_FETCHING_TIMEOUT_SECONDS: int = Field(
20+
180,
21+
description="Timeout for fetching transfers in seconds",
22+
alias="SCHEDULER__TRANSFER_FETCHING_TIMEOUT_SECONDS",
23+
)
24+
MISFIRE_GRACE_TIME_SECONDS: int = Field(
25+
300,
26+
description="Grace time for misfired jobs in seconds",
27+
alias="SCHEDULER__MISFIRE_GRACE_TIME_SECONDS",
28+
)

syncmaster/scheduler/transfer_fetcher.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
# SPDX-License-Identifier: Apache-2.0
33
from sqlalchemy import select
44

5-
from syncmaster.backend.settings import BackendSettings as Settings
65
from syncmaster.db.models import Transfer
6+
from syncmaster.scheduler.settings import SchedulerSettings as Settings
77
from syncmaster.scheduler.utils import get_async_session
88

99

syncmaster/scheduler/transfer_job_manager.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
from kombu.exceptions import KombuError
88

99
from syncmaster.backend.services.unit_of_work import UnitOfWork
10-
from syncmaster.backend.settings import BackendSettings as Settings
1110
from syncmaster.db.models import RunType, Status, Transfer
1211
from syncmaster.exceptions.run import CannotConnectToTaskQueueError
12+
from syncmaster.scheduler.settings import SchedulerSettings as Settings
1313
from syncmaster.scheduler.utils import get_async_session
1414
from syncmaster.schemas.v1.connections.connection import ReadAuthDataSchema
1515
from syncmaster.worker.config import celery
@@ -35,15 +35,15 @@ def update_jobs(self, transfers: list[Transfer]) -> None:
3535
self.scheduler.modify_job(
3636
job_id=job_id,
3737
trigger=CronTrigger.from_crontab(transfer.schedule),
38-
misfire_grace_time=self.settings.SCHEDULER_MISFIRE_GRACE_TIME,
38+
misfire_grace_time=self.settings.MISFIRE_GRACE_TIME_SECONDS,
3939
args=(transfer.id,),
4040
)
4141
else:
4242
self.scheduler.add_job(
4343
func=TransferJobManager.send_job_to_celery,
4444
id=job_id,
4545
trigger=CronTrigger.from_crontab(transfer.schedule),
46-
misfire_grace_time=self.settings.SCHEDULER_MISFIRE_GRACE_TIME,
46+
misfire_grace_time=self.settings.MISFIRE_GRACE_TIME_SECONDS,
4747
args=(transfer.id,),
4848
)
4949

syncmaster/scheduler/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# SPDX-License-Identifier: Apache-2.0
33
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_async_engine
44

5-
from syncmaster.backend.settings import BackendSettings as Settings
5+
from syncmaster.scheduler.settings import SchedulerSettings as Settings
66

77

88
def get_async_session(settings: Settings) -> AsyncSession:

0 commit comments

Comments
 (0)