Set follows gauge on startup

This commit is contained in:
Zeva Rose 2022-06-14 12:44:05 -06:00
parent c022a62e98
commit 3b04182ea2

View file

@ -161,15 +161,15 @@ class JARVISTwitterStream(AsyncStream):
except Exception:
logger.debug(f"Failed to send message to {channel.id} in {channel.guild.name}")
gauge = twitter_gauge.labels(twitter_handle=status.user.screen_name)
gauge.set(num_follows)
if num_follows == 0:
logger.warning(f"Account {status.author.screen_name} no longer has followers, removing")
account = await TwitterAccount.find_one(q(twitter_id=status.author.id))
if account:
await account.delete()
self.disconnect()
else:
gauge = twitter_gauge.labels(twitter_handle=status.user.screen_name)
gauge.set(num_follows)
async def twitter(bot: Client) -> None:
@ -205,6 +205,9 @@ async def twitter(bot: Client) -> None:
if count == 0:
logger.debug(f"Account {account.handle} has no followers, removing")
await account.delete()
else:
gauge = twitter_gauge.labels(twitter_handle=account.handle)
gauge.set(count)
while True:
accounts = TwitterAccount.find()