From cba3643e02bf9067fad89235d779b9bc38130d5d Mon Sep 17 00:00:00 2001 From: bakatrouble Date: Mon, 28 Jan 2019 00:32:34 +0300 Subject: [PATCH] fix imports --- aggregator/models.py | 4 ++-- aggregator/tasks.py | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/aggregator/models.py b/aggregator/models.py index 9c54e1b..39fd543 100644 --- a/aggregator/models.py +++ b/aggregator/models.py @@ -7,8 +7,6 @@ from django.conf import settings from django.db import models from pyrogram import Chat as PyrogramChat, Message as PyrogramMessage -from aggregator.tasks import collect_new_messages - class AggregationSource(models.Model): owner = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE) @@ -28,6 +26,8 @@ class Chat(models.Model): @classmethod def from_obj(cls, chat: PyrogramChat, client): + from aggregator.tasks import collect_new_messages + obj, created = Chat.objects.update_or_create( chat_id=chat.id, defaults={ diff --git a/aggregator/tasks.py b/aggregator/tasks.py index fd76906..a7e0fdf 100644 --- a/aggregator/tasks.py +++ b/aggregator/tasks.py @@ -3,12 +3,13 @@ from celery_once import QueueOnce from aggregator.client import get_client from config.celery import app -from .models import Chat from .client import collect_new_messages as _collect_new_messages @app.task(base=QueueOnce, once={'keys': ['chat_id'], 'graceful': True}) def collect_new_messages(chat_id): + from .models import Chat + chat = Chat.objects.get(pk=chat_id) with get_client() as client: _collect_new_messages(client, chat)