fix tracker auto update
This commit is contained in:
		
							parent
							
								
									a928340b6b
								
							
						
					
					
						commit
						74cbfe07a3
					
				
							
								
								
									
										21
									
								
								WebHost.py
								
								
								
								
							
							
						
						
									
										21
									
								
								WebHost.py
								
								
								
								
							|  | @ -10,6 +10,25 @@ from WebHost.models import db | ||||||
| DEBUG = False | DEBUG = False | ||||||
| port = 80 | port = 80 | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
|  | def autohost(config: dict): | ||||||
|  |     from WebHost.models import * | ||||||
|  |     import time | ||||||
|  |     from datetime import timedelta, datetime | ||||||
|  | 
 | ||||||
|  |     def keep_running(): | ||||||
|  |         db.bind(**config["pony"]) | ||||||
|  |         db.generate_mapping(check_tables=False) | ||||||
|  |         while 1: | ||||||
|  |             time.sleep(3) | ||||||
|  |             with db_session: | ||||||
|  |                 select( | ||||||
|  |                     room for room in Room if (datetime.utcnow() - room.last_activity) < timedelta(hours=room.timeout)) | ||||||
|  | 
 | ||||||
|  |     import threading | ||||||
|  |     threading.Thread(target=keep_running).start() | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| if __name__ == "__main__": | if __name__ == "__main__": | ||||||
|     multiprocessing.freeze_support() |     multiprocessing.freeze_support() | ||||||
|     multiprocessing.set_start_method('spawn') |     multiprocessing.set_start_method('spawn') | ||||||
|  | @ -19,7 +38,6 @@ if __name__ == "__main__": | ||||||
| 
 | 
 | ||||||
|     if os.path.exists(configpath): |     if os.path.exists(configpath): | ||||||
|         import yaml |         import yaml | ||||||
| 
 |  | ||||||
|         with open(configpath) as c: |         with open(configpath) as c: | ||||||
|             app.config.update(yaml.safe_load(c)) |             app.config.update(yaml.safe_load(c)) | ||||||
| 
 | 
 | ||||||
|  | @ -27,6 +45,7 @@ if __name__ == "__main__": | ||||||
|     db.bind(**app.config["PONY"]) |     db.bind(**app.config["PONY"]) | ||||||
|     db.generate_mapping(create_tables=True) |     db.generate_mapping(create_tables=True) | ||||||
|     if DEBUG: |     if DEBUG: | ||||||
|  |         autohost(config) | ||||||
|         app.run(debug=True, port=port) |         app.run(debug=True, port=port) | ||||||
|     else: |     else: | ||||||
|         serve(app, port=port, threads=app.config["WAITRESS_THREADS"]) |         serve(app, port=port, threads=app.config["WAITRESS_THREADS"]) | ||||||
|  |  | ||||||
|  | @ -21,7 +21,7 @@ | ||||||
| 
 | 
 | ||||||
|             function update() { |             function update() { | ||||||
|                 var target = $("<div></div>"); |                 var target = $("<div></div>"); | ||||||
|                 target.load("/tracker/{{ room.tracker.id }}", function (response, status) { |                 target.load("/tracker/{{ room.tracker }}", function (response, status) { | ||||||
|                     if (status === "success") { |                     if (status === "success") { | ||||||
|                         target.find(".table").each(function (i, new_table) { |                         target.find(".table").each(function (i, new_table) { | ||||||
|                             var new_trs = $(new_table).find("tbody>tr"); |                             var new_trs = $(new_table).find("tbody>tr"); | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue