Features: 1) Added custom queues to all Celery tasks for more granular processing; 2) Implemented sensitive data scrubbing in Sentry error reporting.
Fixes: None; Extra: Refactored Sentry initialization to include `before_send` callback and improved settings structure.
This commit is contained in:
parent
8bc7104109
commit
7722eef0a3
6 changed files with 41 additions and 18 deletions
|
|
@ -19,7 +19,7 @@ from evibes.settings import MEDIA_ROOT
|
|||
logger = get_task_logger(__name__)
|
||||
|
||||
|
||||
@shared_task
|
||||
@shared_task(queue="stock_updater")
|
||||
def update_products_task():
|
||||
"""
|
||||
Run a background task to update product data and manage stale products.
|
||||
|
|
@ -54,7 +54,7 @@ def update_products_task():
|
|||
return True, "Success"
|
||||
|
||||
|
||||
@shared_task
|
||||
@shared_task(queue="default")
|
||||
def update_orderproducts_task():
|
||||
"""
|
||||
Updates the statuses of order products for all vendors listed in the
|
||||
|
|
@ -76,7 +76,7 @@ def update_orderproducts_task():
|
|||
return True, "Success"
|
||||
|
||||
|
||||
@shared_task
|
||||
@shared_task(queue="default")
|
||||
def set_default_caches_task():
|
||||
"""
|
||||
Task to set default caches in the application's memory.
|
||||
|
|
@ -92,7 +92,7 @@ def set_default_caches_task():
|
|||
return True, "Success"
|
||||
|
||||
|
||||
@shared_task
|
||||
@shared_task(queue="default")
|
||||
def remove_stale_product_images():
|
||||
"""
|
||||
Removes stale product images from the products directory by identifying directories
|
||||
|
|
@ -139,7 +139,7 @@ def remove_stale_product_images():
|
|||
logger.error("Error removing directory %s: %s", entry_path, e)
|
||||
|
||||
|
||||
@shared_task
|
||||
@shared_task(queue="default")
|
||||
def process_promotions() -> tuple[bool, str]:
|
||||
"""
|
||||
Processes and updates promotions based on holiday data or default settings.
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ from core.models import Order, OrderProduct
|
|||
from core.utils.constance import set_email_settings
|
||||
|
||||
|
||||
@shared_task
|
||||
@shared_task(queue="default")
|
||||
def contact_us_email(contact_info):
|
||||
set_email_settings()
|
||||
connection = mail.get_connection()
|
||||
|
|
@ -40,7 +40,7 @@ def contact_us_email(contact_info):
|
|||
return True, str(contact_info.get("email"))
|
||||
|
||||
|
||||
@shared_task
|
||||
@shared_task(queue="default")
|
||||
def send_order_created_email(order_pk: str) -> tuple[bool, str]:
|
||||
try:
|
||||
order = Order.objects.get(pk=order_pk)
|
||||
|
|
@ -74,7 +74,7 @@ def send_order_created_email(order_pk: str) -> tuple[bool, str]:
|
|||
return True, str(order.uuid)
|
||||
|
||||
|
||||
@shared_task
|
||||
@shared_task(queue="default")
|
||||
def send_order_finished_email(order_pk: str) -> tuple[bool, str]:
|
||||
def send_digital_assets_email(ops: list[OrderProduct]):
|
||||
if len(ops) <= 0:
|
||||
|
|
|
|||
|
|
@ -281,13 +281,32 @@ if getenv("SENTRY_DSN"):
|
|||
from sentry_sdk.integrations.logging import LoggingIntegration
|
||||
from sentry_sdk.integrations.redis import RedisIntegration
|
||||
|
||||
ignore_errors: list[str] = [
|
||||
]
|
||||
def scrub_sensitive(data):
|
||||
if isinstance(data, dict):
|
||||
cleaned = {}
|
||||
for key, value in data.items():
|
||||
if key.lower() in ("password", "confirm_password"):
|
||||
cleaned[key] = "[FILTERED]"
|
||||
else:
|
||||
cleaned[key] = scrub_sensitive(value)
|
||||
return cleaned
|
||||
if isinstance(data, list):
|
||||
return [scrub_sensitive(item) for item in data]
|
||||
return data
|
||||
|
||||
def before_send(event, hint):
|
||||
if hint:
|
||||
pass
|
||||
request = event.get("request", {})
|
||||
if "data" in request:
|
||||
request["data"] = scrub_sensitive(request["data"])
|
||||
event["request"] = request
|
||||
return event
|
||||
|
||||
ignore_errors: list[str] = []
|
||||
|
||||
sentry_sdk.init(
|
||||
dsn=getenv("SENTRY_DSN"),
|
||||
traces_sample_rate=1.0 if DEBUG else 0.2,
|
||||
profiles_sample_rate=1.0 if DEBUG else 0.1,
|
||||
integrations=[
|
||||
DjangoIntegration(),
|
||||
LoggingIntegration(level=logging.INFO, event_level=logging.ERROR),
|
||||
|
|
@ -295,9 +314,13 @@ if getenv("SENTRY_DSN"):
|
|||
RedisIntegration(),
|
||||
],
|
||||
environment="development" if DEBUG else "production",
|
||||
debug=False,
|
||||
release=f"evibes@{EVIBES_VERSION}",
|
||||
traces_sample_rate=1.0 if DEBUG else 0.2,
|
||||
profiles_sample_rate=1.0 if DEBUG else 0.1,
|
||||
max_request_body_size="always",
|
||||
before_send=before_send,
|
||||
ignore_errors=ignore_errors,
|
||||
debug=False,
|
||||
)
|
||||
|
||||
SESSION_COOKIE_HTTPONLY: bool = True
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ from core.utils.constance import set_email_settings
|
|||
from payments.models import Transaction
|
||||
|
||||
|
||||
@shared_task
|
||||
@shared_task(queue="default")
|
||||
def balance_deposit_email(transaction_pk: str) -> tuple[bool, str]:
|
||||
try:
|
||||
transaction = Transaction.objects.get(pk=transaction_pk)
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ from core.models import Order, Wishlist
|
|||
from vibes_auth.models import User
|
||||
|
||||
|
||||
@shared_task
|
||||
@shared_task(queue="default")
|
||||
def create_pending_order(user_uuid):
|
||||
try:
|
||||
user = User.objects.get(uuid=user_uuid)
|
||||
|
|
@ -14,7 +14,7 @@ def create_pending_order(user_uuid):
|
|||
return False, f"Bad uuid was given: {user_uuid}"
|
||||
|
||||
|
||||
@shared_task
|
||||
@shared_task(queue="default")
|
||||
def create_wishlist(user_uuid):
|
||||
try:
|
||||
user = User.objects.get(uuid=user_uuid)
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ from core.utils.constance import set_email_settings
|
|||
from vibes_auth.models import User
|
||||
|
||||
|
||||
@shared_task
|
||||
@shared_task(queue="default")
|
||||
def send_verification_email_task(user_pk: str) -> tuple[bool, str]:
|
||||
try:
|
||||
user = User.objects.get(pk=user_pk)
|
||||
|
|
@ -55,7 +55,7 @@ def send_verification_email_task(user_pk: str) -> tuple[bool, str]:
|
|||
return True, user.uuid
|
||||
|
||||
|
||||
@shared_task
|
||||
@shared_task(queue="default")
|
||||
def send_reset_password_email_task(user_pk: str) -> tuple[bool, str]:
|
||||
try:
|
||||
user = User.objects.get(pk=user_pk)
|
||||
|
|
|
|||
Loading…
Reference in a new issue