Skip to content

Commit

Permalink
add Redis & celery
Browse files Browse the repository at this point in the history
  • Loading branch information
ATOUIYakoub committed Sep 17, 2024
1 parent b1c54ae commit a76389f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
10 changes: 10 additions & 0 deletions analytics/tasks.py
Original file line number Diff line number Diff line change
@@ -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()}
22 changes: 22 additions & 0 deletions crm_analytics/celery_app.py
Original file line number Diff line number Diff line change
@@ -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}')

0 comments on commit a76389f

Please sign in to comment.