Add CALL logging to the watch loop
This commit is contained in:
1 parent
1cc4c4d1c3
commit
cb8d76b602
1 file changed
+29
-8
@@ -954,10 +954,10 @@ class Twitch:
|
|||||||
|
|
||||||
@task_wrapper
|
@task_wrapper
|
||||||
async def _watch_loop(self) -> NoReturn:
|
async def _watch_loop(self) -> NoReturn:
|
||||||
interval = WATCH_INTERVAL.total_seconds()
|
interval: float = WATCH_INTERVAL.total_seconds()
|
||||||
while True:
|
while True:
|
||||||
channel = await self.watching_channel.get()
|
channel: Channel = await self.watching_channel.get()
|
||||||
succeeded = await channel.send_watch()
|
succeeded: bool = await channel.send_watch()
|
||||||
if not succeeded:
|
if not succeeded:
|
||||||
# this usually means the campaign expired in the middle of mining
|
# this usually means the campaign expired in the middle of mining
|
||||||
# NOTE: the maintenance task should switch the channel right after this happens
|
# NOTE: the maintenance task should switch the channel right after this happens
|
||||||
@@ -965,13 +965,14 @@ class Twitch:
|
|||||||
continue
|
continue
|
||||||
last_watch = time()
|
last_watch = time()
|
||||||
self._drop_update = asyncio.Future()
|
self._drop_update = asyncio.Future()
|
||||||
use_active = False
|
use_active: bool = False
|
||||||
try:
|
try:
|
||||||
handled = await asyncio.wait_for(self._drop_update, timeout=10)
|
handled: bool = await asyncio.wait_for(self._drop_update, timeout=10)
|
||||||
except asyncio.TimeoutError:
|
except asyncio.TimeoutError:
|
||||||
# there was no websocket update within 10s
|
# there was no websocket update within 10s
|
||||||
handled = False
|
handled = False
|
||||||
use_active = True
|
use_active = True
|
||||||
|
logger.log(CALL, "No drop update from the websocket received")
|
||||||
self._drop_update = None
|
self._drop_update = None
|
||||||
if not handled:
|
if not handled:
|
||||||
# websocket update timed out, or the update was for an unrelated drop
|
# websocket update timed out, or the update was for an unrelated drop
|
||||||
@@ -982,18 +983,31 @@ class Twitch:
|
|||||||
context["data"]["currentUser"]["dropCurrentSession"]
|
context["data"]["currentUser"]["dropCurrentSession"]
|
||||||
)
|
)
|
||||||
if drop_data is not None:
|
if drop_data is not None:
|
||||||
drop_id = drop_data["dropID"]
|
drop = self._drops.get(drop_data["dropID"])
|
||||||
drop = self._drops.get(drop_id)
|
|
||||||
if drop is None:
|
if drop is None:
|
||||||
use_active = True
|
use_active = True
|
||||||
logger.error(f"Missing drop: {drop_id}")
|
# usually this means there was a campaign changed between reloads
|
||||||
|
logger.info("Missing drop detected, reloading...")
|
||||||
|
self.change_state(State.INVENTORY_FETCH)
|
||||||
elif not drop.can_earn(channel):
|
elif not drop.can_earn(channel):
|
||||||
|
# we can't earn this drop in the current watching channel
|
||||||
use_active = True
|
use_active = True
|
||||||
|
drop_text = (
|
||||||
|
f"{drop.name} ({drop.campaign.game}, "
|
||||||
|
f"{drop.current_minutes}/{drop.required_minutes})"
|
||||||
|
)
|
||||||
|
logger.log(CALL, f"Current drop returned mismach: {drop_text}")
|
||||||
else:
|
else:
|
||||||
drop.update_minutes(drop_data["currentMinutesWatched"])
|
drop.update_minutes(drop_data["currentMinutesWatched"])
|
||||||
drop.display()
|
drop.display()
|
||||||
|
drop_text = (
|
||||||
|
f"{drop.name} ({drop.campaign.game}, "
|
||||||
|
f"{drop.current_minutes}/{drop.required_minutes})"
|
||||||
|
)
|
||||||
|
logger.log(CALL, f"Drop progress from GQL: {drop_text}")
|
||||||
else:
|
else:
|
||||||
use_active = True
|
use_active = True
|
||||||
|
logger.log(CALL, "Current drop returned as none")
|
||||||
if use_active:
|
if use_active:
|
||||||
# Sometimes, even GQL fails to give us the correct drop.
|
# Sometimes, even GQL fails to give us the correct drop.
|
||||||
# In that case, we can use the locally cached inventory to try
|
# In that case, we can use the locally cached inventory to try
|
||||||
@@ -1003,6 +1017,13 @@ class Twitch:
|
|||||||
if (drop := self.get_active_drop()) is not None:
|
if (drop := self.get_active_drop()) is not None:
|
||||||
drop.bump_minutes()
|
drop.bump_minutes()
|
||||||
drop.display()
|
drop.display()
|
||||||
|
drop_text = (
|
||||||
|
f"{drop.name} ({drop.campaign.game}, "
|
||||||
|
f"{drop.current_minutes}/{drop.required_minutes})"
|
||||||
|
)
|
||||||
|
logger.log(CALL, f"Drop progress from active search: {drop_text}")
|
||||||
|
else:
|
||||||
|
logger.log(CALL, "No active drop could be determined")
|
||||||
await self._watch_sleep(last_watch + interval - time())
|
await self._watch_sleep(last_watch + interval - time())
|
||||||
|
|
||||||
@task_wrapper
|
@task_wrapper
|
||||||
|
|||||||
Reference in new issue
Block a user