From a76389ff477015df249d13914e07e47b90daf58d Mon Sep 17 00:00:00 2001 From: ATOUIYakoub Date: Tue, 17 Sep 2024 11:35:04 +0100 Subject: [PATCH] add Redis & celery --- analytics/tasks.py | 10 ++++++++++ crm_analytics/celery_app.py | 22 ++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 analytics/tasks.py create mode 100644 crm_analytics/celery_app.py diff --git a/analytics/tasks.py b/analytics/tasks.py new file mode 100644 index 0000000..fb21030 --- /dev/null +++ b/analytics/tasks.py @@ -0,0 +1,10 @@ +from celery import shared_task +from .hubspot import delete_hubspot_lead + +@shared_task +def delete_hubspot_lead_task(lead_id): + response = delete_hubspot_lead(lead_id) + if response.status_code == 204: + return {'status': 'success', 'message': 'Lead deleted successfully'} + else: + return {'status': 'error', 'message': 'Failed to delete lead', 'details': response.json()} \ No newline at end of file diff --git a/crm_analytics/celery_app.py b/crm_analytics/celery_app.py new file mode 100644 index 0000000..c531a2e --- /dev/null +++ b/crm_analytics/celery_app.py @@ -0,0 +1,22 @@ +from __future__ import absolute_import, unicode_literals +import os +from celery import Celery +from django.conf import settings + +# Set the default Django settings module for the 'celery' program. +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'crm_analytics.settings') + +app = Celery('crm_analytics') + +# Using a string here means the worker doesn't have to serialize +# the configuration object to child processes. +# - namespace='CELERY' means all celery-related configuration keys +# should have a `CELERY_` prefix. +app.config_from_object('django.conf:settings', namespace='CELERY') + +# Load task modules from all registered Django app configs. +app.autodiscover_tasks(lambda: settings.INSTALLED_APPS) + +@app.task(bind=True) +def debug_task(self): + print(f'Request: {self.request!r}') \ No newline at end of file