rewritten crap
This commit is contained in:
		@@ -16,29 +16,30 @@ class OzonStocksSender(BaseStocksSender):
 | 
			
		||||
        return 100
 | 
			
		||||
 | 
			
		||||
    async def _process_chunk(self, chunk: list[dict]) -> SendStockStatus:
 | 
			
		||||
        session ,response = await self.api.update_stocks(data=chunk)
 | 
			
		||||
        session, response = await self.api.update_stocks(data=chunk)
 | 
			
		||||
        try:
 | 
			
		||||
            status_code = response.status
 | 
			
		||||
            if status_code == 200:
 | 
			
		||||
                return SendStockStatus.SUCCESS
 | 
			
		||||
            if response.content_type != JSONResponse.media_type:
 | 
			
		||||
            async with response:
 | 
			
		||||
                status_code = response.status
 | 
			
		||||
                if status_code == 200:
 | 
			
		||||
                    return SendStockStatus.SUCCESS
 | 
			
		||||
                if response.content_type != JSONResponse.media_type:
 | 
			
		||||
                    return SendStockStatus.ERROR
 | 
			
		||||
                json_data = await response.json()
 | 
			
		||||
                error_code = json_data.get('code')
 | 
			
		||||
                error_message = json_data.get('message')
 | 
			
		||||
                if error_code == 8:
 | 
			
		||||
                    await asyncio.sleep(1)
 | 
			
		||||
                    return SendStockStatus.SHOULD_RETRY
 | 
			
		||||
                logging.error(f'[{self.updater.marketplace.id}]: {error_message}')
 | 
			
		||||
                if status_code in [
 | 
			
		||||
                    404,
 | 
			
		||||
                    500,
 | 
			
		||||
                ]:
 | 
			
		||||
                    return SendStockStatus.SHOULD_RETRY
 | 
			
		||||
                return SendStockStatus.ERROR
 | 
			
		||||
            json_data = await response.json()
 | 
			
		||||
            error_code = json_data.get('code')
 | 
			
		||||
            error_message = json_data.get('message')
 | 
			
		||||
            if error_code == 8:
 | 
			
		||||
                await asyncio.sleep(1)
 | 
			
		||||
                return SendStockStatus.SHOULD_RETRY
 | 
			
		||||
            logging.error(f'[{self.updater.marketplace.id}]: {error_message}')
 | 
			
		||||
            if status_code in [
 | 
			
		||||
                404,
 | 
			
		||||
                500,
 | 
			
		||||
            ]:
 | 
			
		||||
                return SendStockStatus.SHOULD_RETRY
 | 
			
		||||
            return SendStockStatus.ERROR
 | 
			
		||||
        finally:
 | 
			
		||||
            await response.close()
 | 
			
		||||
            await session.close()
 | 
			
		||||
 | 
			
		||||
    async def after_chunk_processed(self):
 | 
			
		||||
        return await asyncio.sleep(80 / 100)
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user