@@ -21,6 +21,11 @@ class AzurLaneAutoScript:
2121 def __init__ (self , config_name = 'alas' ):
2222 logger .hr ('Start' , level = 0 )
2323 self .config_name = config_name
24+ # Skip first restart
25+ self .is_first_task = True
26+ # Failure count of tasks
27+ # Key: str, task name, value: int, failure count
28+ self .failure_record = {}
2429
2530 @cached_property
2631 def config (self ):
@@ -427,14 +432,15 @@ def get_next_task(self):
427432
428433 if task .next_run > datetime .now ():
429434 logger .info (f'Wait until { task .next_run } for task `{ task .command } `' )
435+ self .is_first_task = False
430436 method = self .config .Optimization_WhenTaskQueueEmpty
431437 if method == 'close_game' :
432438 logger .info ('Close game during wait' )
433439 self .device .app_stop ()
434440 release_resources ()
435441 self .device .release_during_wait ()
436442 if not self .wait_until (task .next_run ):
437- del self . __dict__ [ 'config' ]
443+ del_cached_property ( self , 'config' )
438444 continue
439445 self .run ('start' )
440446 elif method == 'goto_main' :
@@ -443,21 +449,21 @@ def get_next_task(self):
443449 release_resources ()
444450 self .device .release_during_wait ()
445451 if not self .wait_until (task .next_run ):
446- del self . __dict__ [ 'config' ]
452+ del_cached_property ( self , 'config' )
447453 continue
448454 elif method == 'stay_there' :
449455 logger .info ('Stay there during wait' )
450456 release_resources ()
451457 self .device .release_during_wait ()
452458 if not self .wait_until (task .next_run ):
453- del self . __dict__ [ 'config' ]
459+ del_cached_property ( self , 'config' )
454460 continue
455461 else :
456462 logger .warning (f'Invalid Optimization_WhenTaskQueueEmpty: { method } , fallback to stay_there' )
457463 release_resources ()
458464 self .device .release_during_wait ()
459465 if not self .wait_until (task .next_run ):
460- del self . __dict__ [ 'config' ]
466+ del_cached_property ( self , 'config' )
461467 continue
462468 break
463469
@@ -467,8 +473,6 @@ def get_next_task(self):
467473 def loop (self ):
468474 logger .set_file_logger (self .config_name )
469475 logger .info (f'Start scheduler loop: { self .config_name } ' )
470- is_first = True
471- failure_record = {}
472476
473477 while 1 :
474478 # Check update event from GUI
@@ -492,10 +496,10 @@ def loop(self):
492496 # Init device and change server
493497 _ = self .device
494498 # Skip first restart
495- if is_first and task == 'Restart' :
499+ if self . is_first_task and task == 'Restart' :
496500 logger .info ('Skip task `Restart` at scheduler start' )
497501 self .config .task_delay (server_update = True )
498- del self . __dict__ [ 'config' ]
502+ del_cached_property ( self , 'config' )
499503 continue
500504
501505 # Run
@@ -505,12 +509,12 @@ def loop(self):
505509 logger .hr (task , level = 0 )
506510 success = self .run (inflection .underscore (task ))
507511 logger .info (f'Scheduler: End task `{ task } `' )
508- is_first = False
512+ self . is_first_task = False
509513
510514 # Check failures
511- failed = deep_get (failure_record , keys = task , default = 0 )
515+ failed = deep_get (self . failure_record , keys = task , default = 0 )
512516 failed = 0 if success else failed + 1
513- deep_set (failure_record , keys = task , value = failed )
517+ deep_set (self . failure_record , keys = task , value = failed )
514518 if failed >= 3 :
515519 logger .critical (f"Task `{ task } ` failed 3 or more times." )
516520 logger .critical ("Possible reason #1: You haven't used it correctly. "
@@ -526,11 +530,11 @@ def loop(self):
526530 exit (1 )
527531
528532 if success :
529- del self . __dict__ [ 'config' ]
533+ del_cached_property ( self , 'config' )
530534 continue
531535 elif self .config .Error_HandleError :
532536 # self.config.task_delay(success=False)
533- del self . __dict__ [ 'config' ]
537+ del_cached_property ( self , 'config' )
534538 self .checker .check_now ()
535539 continue
536540 else :
0 commit comments