schon/evibes/celery_serializers.py
fureunoir 4c7b40b899 Features: 1) Add orjson serializer and integrate it into Celery configuration for enhanced performance and compatibility; 2) Introduce configurable task settings such as soft and hard time limits, task tracking, and event serialization for better control and observability.
Fixes: 1) Update worker entrypoints to adjust prefetch multiplier and memory/task limits for optimized resource usage.

Extra: 1) Refactor Celery settings into a dedicated file for improved organization and maintainability; 2) Adjust Docker entrypoints to align with updated task configurations; 3) Register `orjson` serializer in a separate module for cleaner code structure.
2026-01-04 18:37:00 +03:00

22 lines
461 B
Python

import orjson
from kombu.serialization import register
def orjson_dumps(obj):
return orjson.dumps(obj, option=orjson.OPT_NON_STR_KEYS).decode("utf-8")
def orjson_loads(data):
if isinstance(data, str):
data = data.encode("utf-8")
return orjson.loads(data)
def register_orjson():
register(
"orjson",
orjson_dumps,
orjson_loads,
content_type="application/json",
content_encoding="utf-8",
)