WebHost: Don't count exit saving as activity, thereby creating a hosting loop
This commit is contained in:
		
							parent
							
								
									cb4d2d1ef0
								
							
						
					
					
						commit
						ac238d9b14
					
				|  | @ -150,7 +150,7 @@ class Context(Node): | ||||||
| 
 | 
 | ||||||
|         return False |         return False | ||||||
| 
 | 
 | ||||||
|     def _save(self) -> bool: |     def _save(self, exit_save:bool=False) -> bool: | ||||||
|         try: |         try: | ||||||
|             jsonstr = json.dumps(self.get_save()) |             jsonstr = json.dumps(self.get_save()) | ||||||
|             with open(self.save_filename, "wb") as f: |             with open(self.save_filename, "wb") as f: | ||||||
|  | @ -192,7 +192,7 @@ class Context(Node): | ||||||
|             self.auto_saver_thread.start() |             self.auto_saver_thread.start() | ||||||
| 
 | 
 | ||||||
|             import atexit |             import atexit | ||||||
|             atexit.register(self._save)  # make sure we save on exit too |             atexit.register(self._save, True)  # make sure we save on exit too | ||||||
| 
 | 
 | ||||||
|     def get_save(self) -> dict: |     def get_save(self) -> dict: | ||||||
|         d = { |         d = { | ||||||
|  | @ -212,8 +212,9 @@ class Context(Node): | ||||||
| 
 | 
 | ||||||
|     def set_save(self, savedata: dict): |     def set_save(self, savedata: dict): | ||||||
|         rom_names = savedata["rom_names"]  # convert from TrackerList to List in case of ponyorm |         rom_names = savedata["rom_names"]  # convert from TrackerList to List in case of ponyorm | ||||||
|         if rom_names != self.rom_names: | 
 | ||||||
|             adjusted = {tuple(rom): (team, slot) for (rom, (team, slot)) in rom_names}  # old format, ponyorm friendly |         if {rom: other for rom, other in rom_names} != self.rom_names: | ||||||
|  |             adjusted = {rom: (team, slot) for (rom, (team, slot)) in rom_names}  # old format, ponyorm friendly | ||||||
|             if self.rom_names != adjusted: |             if self.rom_names != adjusted: | ||||||
|                 logging.warning('Save file mismatch, will start a new game') |                 logging.warning('Save file mismatch, will start a new game') | ||||||
|                 return |                 return | ||||||
|  |  | ||||||
|  | @ -81,11 +81,12 @@ class WebHostContext(Context): | ||||||
|         threading.Thread(target=self.listen_to_db_commands, daemon=True).start() |         threading.Thread(target=self.listen_to_db_commands, daemon=True).start() | ||||||
| 
 | 
 | ||||||
|     @db_session |     @db_session | ||||||
|     def _save(self) -> bool: |     def _save(self, exit_save:bool = False) -> bool: | ||||||
|         room = Room.get(id=self.room_id) |         room = Room.get(id=self.room_id) | ||||||
|         room.multisave = self.get_save() |         room.multisave = self.get_save() | ||||||
|         # saving only occurs on activity, so we can "abuse" this information to mark this as last_activity |         # saving only occurs on activity, so we can "abuse" this information to mark this as last_activity | ||||||
|         room.last_activity = datetime.utcnow() |         if not exit_save: # we don't want to count a shutdown as activity, which would restart the server again | ||||||
|  |             room.last_activity = datetime.utcnow() | ||||||
|         return True |         return True | ||||||
| 
 | 
 | ||||||
|     def get_save(self) -> dict: |     def get_save(self) -> dict: | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue