feat: a lot of a lot
This commit is contained in:
		
							
								
								
									
										0
									
								
								background/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								background/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										14
									
								
								background/celery_app.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								background/celery_app.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,14 @@
 | 
			
		||||
from celery import Celery
 | 
			
		||||
 | 
			
		||||
from backend.config import CELERY_BROKER_URL, CELERY_RESULT_BACKEND
 | 
			
		||||
 | 
			
		||||
celery = Celery(
 | 
			
		||||
    __name__,
 | 
			
		||||
    broker=CELERY_BROKER_URL,
 | 
			
		||||
    backend=CELERY_RESULT_BACKEND
 | 
			
		||||
)
 | 
			
		||||
celery.conf.result_backend_transport_options = {
 | 
			
		||||
    'global_keyprefix': 'crm_'
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
from .tasks import *
 | 
			
		||||
							
								
								
									
										1
									
								
								background/tasks/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								background/tasks/__init__.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1 @@
 | 
			
		||||
from .marketplace import synchronize_marketplace
 | 
			
		||||
							
								
								
									
										20
									
								
								background/tasks/marketplace.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								background/tasks/marketplace.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,20 @@
 | 
			
		||||
import time
 | 
			
		||||
from random import randint
 | 
			
		||||
 | 
			
		||||
from background.celery_app import celery
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@celery.task(name='synchronize_marketplace')
 | 
			
		||||
def synchronize_marketplace(marketplace_id: int):
 | 
			
		||||
    time.sleep(10)
 | 
			
		||||
    if randint(0,10) % 2 == 0:
 | 
			
		||||
        return 1
 | 
			
		||||
    else:
 | 
			
		||||
        raise Exception('Some error')
 | 
			
		||||
    # async with session_maker() as session:
 | 
			
		||||
    #     session: AsyncSession
 | 
			
		||||
    #     marketplace: Optional[Marketplace] = await session.get(Marketplace, marketplace_id)
 | 
			
		||||
    #     if not marketplace:
 | 
			
		||||
    #         return
 | 
			
		||||
    #     controller = MarketplaceControllerFactory.get_controller(session, marketplace)
 | 
			
		||||
    #     await controller.synchronize_products()
 | 
			
		||||
		Reference in New Issue
	
	Block a user