fix imports
This commit is contained in:
		@@ -7,8 +7,6 @@ from django.conf import settings
 | 
				
			|||||||
from django.db import models
 | 
					from django.db import models
 | 
				
			||||||
from pyrogram import Chat as PyrogramChat, Message as PyrogramMessage
 | 
					from pyrogram import Chat as PyrogramChat, Message as PyrogramMessage
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from aggregator.tasks import collect_new_messages
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
class AggregationSource(models.Model):
 | 
					class AggregationSource(models.Model):
 | 
				
			||||||
    owner = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
 | 
					    owner = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
 | 
				
			||||||
@@ -28,6 +26,8 @@ class Chat(models.Model):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    @classmethod
 | 
					    @classmethod
 | 
				
			||||||
    def from_obj(cls, chat: PyrogramChat, client):
 | 
					    def from_obj(cls, chat: PyrogramChat, client):
 | 
				
			||||||
 | 
					        from aggregator.tasks import collect_new_messages
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        obj, created = Chat.objects.update_or_create(
 | 
					        obj, created = Chat.objects.update_or_create(
 | 
				
			||||||
            chat_id=chat.id,
 | 
					            chat_id=chat.id,
 | 
				
			||||||
            defaults={
 | 
					            defaults={
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,12 +3,13 @@ from celery_once import QueueOnce
 | 
				
			|||||||
from aggregator.client import get_client
 | 
					from aggregator.client import get_client
 | 
				
			||||||
from config.celery import app
 | 
					from config.celery import app
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from .models import Chat
 | 
					 | 
				
			||||||
from .client import collect_new_messages as _collect_new_messages
 | 
					from .client import collect_new_messages as _collect_new_messages
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@app.task(base=QueueOnce, once={'keys': ['chat_id'], 'graceful': True})
 | 
					@app.task(base=QueueOnce, once={'keys': ['chat_id'], 'graceful': True})
 | 
				
			||||||
def collect_new_messages(chat_id):
 | 
					def collect_new_messages(chat_id):
 | 
				
			||||||
 | 
					    from .models import Chat
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    chat = Chat.objects.get(pk=chat_id)
 | 
					    chat = Chat.objects.get(pk=chat_id)
 | 
				
			||||||
    with get_client() as client:
 | 
					    with get_client() as client:
 | 
				
			||||||
        _collect_new_messages(client, chat)
 | 
					        _collect_new_messages(client, chat)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user