task services added
This commit is contained in:
0
ServicesTask/app/services/database/=0.20.0
Normal file
0
ServicesTask/app/services/database/=0.20.0
Normal file
18
ServicesTask/app/services/database/Dockerfile
Normal file
18
ServicesTask/app/services/database/Dockerfile
Normal file
@@ -0,0 +1,18 @@
|
||||
FROM python:3.12-slim
|
||||
|
||||
ENV PYTHONDONTWRITEBYTECODE=1 PYTHONUNBUFFERED=1
|
||||
ENV PYTHONPATH=/app
|
||||
|
||||
WORKDIR /
|
||||
|
||||
COPY app/services/database/pyproject.toml ./
|
||||
COPY app/services/database/README.md ./
|
||||
|
||||
COPY app/core ./app/core
|
||||
COPY app/services/common/ ./app/services/common/
|
||||
COPY app/services/database/ ./app/services/database/
|
||||
|
||||
RUN pip install --upgrade pip && pip install --no-cache-dir .
|
||||
RUN mkdir -p /app/data
|
||||
|
||||
CMD ["python", "-m", "app.services.database.main"]
|
||||
0
ServicesTask/app/services/database/README.md
Normal file
0
ServicesTask/app/services/database/README.md
Normal file
0
ServicesTask/app/services/database/__init__.py
Normal file
0
ServicesTask/app/services/database/__init__.py
Normal file
28
ServicesTask/app/services/database/main.py
Normal file
28
ServicesTask/app/services/database/main.py
Normal file
@@ -0,0 +1,28 @@
|
||||
import os
|
||||
import uuid
|
||||
import asyncio
|
||||
|
||||
from app.services.common.service_base_async import ServiceBaseAsync
|
||||
|
||||
|
||||
PRODUCE_ENABLED = os.getenv("PRODUCE_ENABLED", "true").lower() == "true"
|
||||
PRODUCE_BATCH = int(os.getenv("PRODUCE_BATCH", "3")) # her produce tick'inde kaç iş
|
||||
TASK_TYPE = os.getenv("TASK_TYPE", "db-task") # iş tipi (task_id'de de kullanılır)
|
||||
CONSUME_SLEEP_SEC = float(os.getenv("CONSUME_SLEEP_SEC", "0.5")) # işleme süresi simülasyonu (sn)
|
||||
STATIC_IDS = ["2c47f1073a9d4f05aad6c15484894a72", "65827e3452b545d6845e050a503401f3", "5c663088f09d4062b4e567f47335fb1a"]
|
||||
|
||||
|
||||
async def produce(service: ServiceBaseAsync):
|
||||
for biz_id in STATIC_IDS:
|
||||
deterministic_task_id = f"{TASK_TYPE}:{biz_id}"
|
||||
payload = {"id": biz_id, "op": "sync", "source": "db-service"}
|
||||
await service.enqueue(payload, TASK_TYPE, task_id=deterministic_task_id)
|
||||
print(f"[DB] produce tick attempted ids={','.join(STATIC_IDS)}")
|
||||
|
||||
|
||||
async def consume(service: ServiceBaseAsync, job: dict):
|
||||
await asyncio.sleep(CONSUME_SLEEP_SEC)
|
||||
print(f"[DB] consumed task={job['task_id']}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(ServiceBaseAsync(produce, consume).run())
|
||||
36
ServicesTask/app/services/database/pyproject.toml
Normal file
36
ServicesTask/app/services/database/pyproject.toml
Normal file
@@ -0,0 +1,36 @@
|
||||
[build-system]
|
||||
requires = ["setuptools>=61.0"]
|
||||
build-backend = "setuptools.build_meta"
|
||||
|
||||
[project]
|
||||
name = "dual-queue-services"
|
||||
version = "0.1.0"
|
||||
description = "Async dual queue system with Redis Streams and SQLite persistence"
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.11"
|
||||
authors = [
|
||||
{ name = "Berkay Karatay", email = "karatay.berkay@gmail.com" }
|
||||
]
|
||||
dependencies = [
|
||||
"nats-py>=2.6.0",
|
||||
"prometheus-client>=0.20.0",
|
||||
"uvloop>=0.19.0"
|
||||
]
|
||||
|
||||
[project.optional-dependencies]
|
||||
dev = [
|
||||
"pytest>=7.4",
|
||||
"black>=23.0",
|
||||
"isort>=5.12"
|
||||
]
|
||||
|
||||
[tool.black]
|
||||
line-length = 88
|
||||
target-version = ["py311"]
|
||||
|
||||
[tool.isort]
|
||||
profile = "black"
|
||||
|
||||
[tool.setuptools.packages.find]
|
||||
where = ["app"]
|
||||
include = ["app*"]
|
||||
Reference in New Issue
Block a user