task services added

This commit is contained in:
2025-08-15 22:30:21 +03:00
parent 456203f5cf
commit 9543d136aa
38 changed files with 1065 additions and 0 deletions

View 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"]

View 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())

View 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*"]