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

Commit

Permalink
feat(farmer): imp 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 Jul 6, 2023
1 parent 72c8d69 commit a2f1bc8
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lokbot/farmer.py
Original file line number Diff line number Diff line change
Expand Up @@ -684,8 +684,8 @@ def socf_thread(self, radius, object_code_list=(OBJECT_CODE_CRYSTAL_MINE, OBJECT
websocket connection of the field
:return:
"""
while self.api.last_requested_at + 6 > time.time():
# if last request is less than 6 seconds ago, wait
while self.api.last_requested_at + 16 > time.time():
# if last request is less than 16 seconds ago, wait
# when we are in the field, we should not be doing anything else
logger.info(f'last requested at {arrow.get(self.api.last_requested_at).humanize()}, waiting...')
time.sleep(4)
Expand Down Expand Up @@ -1051,6 +1051,11 @@ def train_troop_thread(self, troop_code, speedup=False, interval=3600):
:param speedup:
:return:
"""
while self.api.last_requested_at + 4 > time.time():
# attempt to prevent `insufficient_resources` due to race conditions
logger.info(f'last requested at {arrow.get(self.api.last_requested_at).humanize()}, waiting...')
time.sleep(4)

self.kingdom_tasks = self.api.kingdom_task_all().get('kingdomTasks', [])

worker_used = [t for t in self.kingdom_tasks if t.get('code') == TASK_CODE_CAMP]
Expand Down

0 comments on commit a2f1bc8

Please sign in to comment.