refactoring celery integration logic