Minor watch loop and mnt task changes
This commit is contained in:
1 parent
ede42e4589
commit
1f4a177906
1 file changed
+5
-6
@@ -416,6 +416,7 @@ class Twitch:
|
|||||||
succeeded = await channel.send_watch()
|
succeeded = 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
|
||||||
await self._watch_sleep(60)
|
await self._watch_sleep(60)
|
||||||
continue
|
continue
|
||||||
last_watch = time()
|
last_watch = time()
|
||||||
@@ -458,8 +459,6 @@ 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()
|
||||||
else:
|
|
||||||
logger.error("Active drop search failed")
|
|
||||||
await self._watch_sleep(last_watch + interval - time())
|
await self._watch_sleep(last_watch + interval - time())
|
||||||
|
|
||||||
@task_wrapper
|
@task_wrapper
|
||||||
@@ -469,10 +468,10 @@ class Twitch:
|
|||||||
while self._state is State.INVENTORY_FETCH:
|
while self._state is State.INVENTORY_FETCH:
|
||||||
await asyncio.sleep(5)
|
await asyncio.sleep(5)
|
||||||
# figure out the maximum sleep period
|
# figure out the maximum sleep period
|
||||||
# 1h at max, but can be shorter if there's a campaign state change earlier than that
|
# max period time can be shorter if there's a campaign state change earlier than that
|
||||||
# divide the period into up to two evenly spaced checks (usually ~15-30m)
|
# divide the period into up to two evenly spaced checks (usually ~15-30m)
|
||||||
now = datetime.now(timezone.utc)
|
now = datetime.now(timezone.utc)
|
||||||
one_hour = timedelta(hours=1)
|
max_period = timedelta(hours=1)
|
||||||
period = timedelta.max
|
period = timedelta.max
|
||||||
for campaign in self.inventory:
|
for campaign in self.inventory:
|
||||||
if not campaign.linked:
|
if not campaign.linked:
|
||||||
@@ -482,8 +481,8 @@ class Twitch:
|
|||||||
period = test_period
|
period = test_period
|
||||||
elif campaign.ends_at >= now and (test_period := campaign.ends_at - now) < period:
|
elif campaign.ends_at >= now and (test_period := campaign.ends_at - now) < period:
|
||||||
period = test_period
|
period = test_period
|
||||||
if period > one_hour:
|
if period > max_period:
|
||||||
period = one_hour
|
period = max_period
|
||||||
times = ceil(period / timedelta(minutes=30))
|
times = ceil(period / timedelta(minutes=30))
|
||||||
period /= times
|
period /= times
|
||||||
for i in range(times):
|
for i in range(times):
|
||||||
|
|||||||
Reference in new issue
Block a user