implement a functioning scheduler, get rid of threads
This commit is contained in:
		
							parent
							
								
									54be2516fe
								
							
						
					
					
						commit
						bee10a2e89
					
				
					 5 changed files with 44 additions and 89 deletions
				
			
		
							
								
								
									
										14
									
								
								pgbot
									
										
									
									
									
								
							
							
						
						
									
										14
									
								
								pgbot
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -1,5 +1,6 @@
 | 
			
		|||
#!/usr/bin/env python3
 | 
			
		||||
 | 
			
		||||
import asyncio
 | 
			
		||||
import sys
 | 
			
		||||
import threading
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -8,9 +9,9 @@ import yaml
 | 
			
		|||
 | 
			
		||||
import pgbotlib.dbstuff
 | 
			
		||||
import pgbotlib.commands
 | 
			
		||||
import pgbotlib.cron
 | 
			
		||||
import pgbotlib.misc
 | 
			
		||||
import pgbotlib.response
 | 
			
		||||
import pgbotlib.sched
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def init(args: list) -> tuple:
 | 
			
		||||
| 
						 | 
				
			
			@ -38,12 +39,6 @@ def main():
 | 
			
		|||
    commander = pgbotlib.commands.Commander(config, client, config['admins'],
 | 
			
		||||
                                            db_conn, namegen, responder)
 | 
			
		||||
 | 
			
		||||
    sched_thread = threading.Thread(
 | 
			
		||||
            target=pgbotlib.sched.spawn_scheduler,
 | 
			
		||||
            args=(config, client, responder),
 | 
			
		||||
            daemon=True)
 | 
			
		||||
    sched_thread.start()
 | 
			
		||||
 | 
			
		||||
    @client.on(telethon.events.NewMessage())
 | 
			
		||||
    async def handle_new_message(event):
 | 
			
		||||
        if event.message.text.startswith('/'):
 | 
			
		||||
| 
						 | 
				
			
			@ -51,7 +46,10 @@ def main():
 | 
			
		|||
        else:
 | 
			
		||||
            await responder.respond(event)
 | 
			
		||||
 | 
			
		||||
    client.run_until_disconnected()
 | 
			
		||||
    cron = pgbotlib.cron.Cron(config, client, responder)
 | 
			
		||||
    cron.plan()
 | 
			
		||||
    loop = asyncio.get_event_loop()
 | 
			
		||||
    loop.run_forever()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
if __name__ == '__main__':
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue