Skip to content
This repository has been archived by the owner on Nov 30, 2023. It is now read-only.

Commit

Permalink
feat(farmer): add exception handler for train_troop_thread
Browse files Browse the repository at this point in the history
Signed-off-by: hldh214 <[email protected]>
  • Loading branch information
hldh214 committed Nov 7, 2023
1 parent 3c23f54 commit b8b2833
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lokbot/farmer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1175,7 +1175,7 @@ def train_troop_thread(self, troop_code, speedup=False, interval=3600):
threading.Thread(target=self.train_troop_thread, args=[troop_code, speedup, interval]).start()
return

# if there is not enough resource, train how much possible
# if there are not enough resources, train how much possible
total_troops_capacity_according_to_resources = self._total_troops_capacity_according_to_resources(troop_code)
if troop_training_capacity > total_troops_capacity_according_to_resources:
troop_training_capacity = total_troops_capacity_according_to_resources
Expand All @@ -1185,7 +1185,12 @@ def train_troop_thread(self, troop_code, speedup=False, interval=3600):
threading.Timer(3600, self.train_troop_thread, [troop_code, speedup, interval]).start()
return

res = self.api.train_troop(troop_code, troop_training_capacity)
try:
res = self.api.train_troop(troop_code, troop_training_capacity)
except OtherException as error_code:
logger.info(f'train_troop: {error_code}, sleep for 1h')
threading.Timer(3600, self.train_troop_thread, [troop_code, speedup, interval]).start()
return

if speedup:
self.do_speedup(res.get('newTask').get('expectedEnded'), res.get('newTask').get('_id'), 'train')
Expand Down Expand Up @@ -1263,7 +1268,7 @@ def alliance_farmer(self, gift_claim=True, help_all=True, research_donate=True,
if research_donate:
self._alliance_research_donate_all()

if shop_auto_buy_item_code_list and type(shop_auto_buy_item_code_list) == list:
if shop_auto_buy_item_code_list and type(shop_auto_buy_item_code_list) is list:
self._alliance_shop_autobuy(shop_auto_buy_item_code_list)

def caravan_farmer(self):
Expand Down

0 comments on commit b8b2833

Please sign in to comment.