task services added
This commit is contained in:
18
ServicesTask/app/services/queue/Dockerfile
Normal file
18
ServicesTask/app/services/queue/Dockerfile
Normal file
@@ -0,0 +1,18 @@
|
||||
FROM python:3.12-slim
|
||||
|
||||
ENV PYTHONDONTWRITEBYTECODE=1 PYTHONUNBUFFERED=1
|
||||
ENV PYTHONPATH=/app
|
||||
|
||||
WORKDIR /
|
||||
|
||||
COPY app/services/queue/pyproject.toml ./
|
||||
COPY app/services/queue/README.md ./
|
||||
|
||||
COPY app/core ./app/core
|
||||
COPY app/services/common/ ./app/services/common/
|
||||
COPY app/services/queue/ ./app/services/queue/
|
||||
|
||||
RUN pip install --upgrade pip && pip install --no-cache-dir .
|
||||
RUN mkdir -p /app/data
|
||||
|
||||
CMD ["python", "-m", "app.services.queue.main"]
|
||||
0
ServicesTask/app/services/queue/README.md
Normal file
0
ServicesTask/app/services/queue/README.md
Normal file
0
ServicesTask/app/services/queue/__init__.py
Normal file
0
ServicesTask/app/services/queue/__init__.py
Normal file
17
ServicesTask/app/services/queue/main.py
Normal file
17
ServicesTask/app/services/queue/main.py
Normal file
@@ -0,0 +1,17 @@
|
||||
import uuid
|
||||
import asyncio
|
||||
|
||||
from app.services.common.service_base_async import ServiceBaseAsync
|
||||
|
||||
async def produce(service: ServiceBaseAsync):
|
||||
print(f"Queue Reader Service up and running.")
|
||||
while True:
|
||||
await asyncio.sleep(1)
|
||||
|
||||
async def consume(service: ServiceBaseAsync, job: dict):
|
||||
await asyncio.sleep(0.1)
|
||||
print(f"Queue Sender Service up and running. Job: {job}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(ServiceBaseAsync(produce, consume).run())
|
||||
35
ServicesTask/app/services/queue/pyproject.toml
Normal file
35
ServicesTask/app/services/queue/pyproject.toml
Normal file
@@ -0,0 +1,35 @@
|
||||
[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 = [
|
||||
"redis>=5.0.0",
|
||||
"aiosqlite>=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*"]
|
||||
16
ServicesTask/app/services/queue/queue_service_async.py
Normal file
16
ServicesTask/app/services/queue/queue_service_async.py
Normal file
@@ -0,0 +1,16 @@
|
||||
import asyncio
|
||||
|
||||
from services.service_base_async import ServiceBaseAsync
|
||||
|
||||
|
||||
async def produce(service: ServiceBaseAsync):
|
||||
fake_jobs = [{"action": "cleanup", "target": "old-tasks"}]
|
||||
for job in fake_jobs:
|
||||
await service.enqueue(job, "queue-maintenance")
|
||||
|
||||
async def consume(service: ServiceBaseAsync, job: dict):
|
||||
print(f"[QUEUE CONTROL] İşleme alındı: {job}")
|
||||
await asyncio.sleep(0.05)
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(ServiceBaseAsync(produce, consume).run())
|
||||
Reference in New Issue
Block a user