use asyncio.sleep instead of time.sleep in cron tasks
This commit is contained in:
		
							parent
							
								
									6da6769c25
								
							
						
					
					
						commit
						29d8ff41c5
					
				
					 1 changed files with 3 additions and 2 deletions
				
			
		| 
						 | 
				
			
			@ -1,4 +1,4 @@
 | 
			
		|||
import time
 | 
			
		||||
import asyncio
 | 
			
		||||
import random
 | 
			
		||||
 | 
			
		||||
import yaml
 | 
			
		||||
| 
						 | 
				
			
			@ -21,7 +21,8 @@ class Cron:
 | 
			
		|||
        tokens = frozenset(job['tokens'].split(','))
 | 
			
		||||
        async def send_message() -> None:
 | 
			
		||||
            if 'rand' in job:
 | 
			
		||||
                time.sleep(random.randint(0, job['rand']) * 60)
 | 
			
		||||
                wait_seconds = random.randint(0, job['rand']) * 60
 | 
			
		||||
                await asyncio.sleep(wait_seconds)
 | 
			
		||||
            message = self.responder.get_response(tokens)
 | 
			
		||||
            message = self.responder.api_match(message, '')
 | 
			
		||||
            await self.client.send_message(job['chat'], message)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue