rewritten crap
This commit is contained in:
		@@ -19,27 +19,29 @@ class WildberriesStocksSender(BaseStocksSender):
 | 
			
		||||
        return 5
 | 
			
		||||
 | 
			
		||||
    async def _process_chunk(self, chunk: list[dict]) -> SendStockStatus:
 | 
			
		||||
        response = await self.api.update_stocks(chunk)
 | 
			
		||||
        headers = response.headers
 | 
			
		||||
        status_code = response.status
 | 
			
		||||
        session,response = await self.api.update_stocks(chunk)
 | 
			
		||||
        try:
 | 
			
		||||
            headers = response.headers
 | 
			
		||||
            status_code = response.status
 | 
			
		||||
 | 
			
		||||
        if status_code in [
 | 
			
		||||
            401,  # Invalid token
 | 
			
		||||
            403,  # Access denied
 | 
			
		||||
            404,  # Not found
 | 
			
		||||
            400,  # Other
 | 
			
		||||
        ]:
 | 
			
		||||
            return SendStockStatus.ERROR
 | 
			
		||||
 | 
			
		||||
        # If there is rate limit
 | 
			
		||||
        if status_code == 429:
 | 
			
		||||
            delay_time = float(headers.get('X-Ratelimit-Reset', self.sleep_time))
 | 
			
		||||
            await asyncio.sleep(delay_time)
 | 
			
		||||
            self.remaining = int(headers.get('X-Ratelimit-Limit', 1))
 | 
			
		||||
            return SendStockStatus.SHOULD_RETRY
 | 
			
		||||
        self.remaining = int(headers.get('X-Ratelimit-Remaining', 0))
 | 
			
		||||
        return SendStockStatus.SUCCESS
 | 
			
		||||
            if status_code in [
 | 
			
		||||
                401,  # Invalid token
 | 
			
		||||
                403,  # Access denied
 | 
			
		||||
                404,  # Not found
 | 
			
		||||
                400,  # Other
 | 
			
		||||
            ]:
 | 
			
		||||
                return SendStockStatus.ERROR
 | 
			
		||||
 | 
			
		||||
            # If there is rate limit
 | 
			
		||||
            if status_code == 429:
 | 
			
		||||
                delay_time = float(headers.get('X-Ratelimit-Reset', self.sleep_time))
 | 
			
		||||
                await asyncio.sleep(delay_time)
 | 
			
		||||
                self.remaining = int(headers.get('X-Ratelimit-Limit', 1))
 | 
			
		||||
                return SendStockStatus.SHOULD_RETRY
 | 
			
		||||
            self.remaining = int(headers.get('X-Ratelimit-Remaining', 0))
 | 
			
		||||
            return SendStockStatus.SUCCESS
 | 
			
		||||
        finally:
 | 
			
		||||
            await session.close()
 | 
			
		||||
    async def after_chunk_processed(self):
 | 
			
		||||
        if self.remaining <= 0:
 | 
			
		||||
            await asyncio.sleep(self.sleep_time)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user