mirror of
https://github.com/kaaninchen/Gleiswechsel.git
synced 2026-09-17 16:52:47 +00:00
fix: asyncio aufrufe abbrechen, damit nicht mehrere tasks gleichzeitig laufen
This commit is contained in:
+7
-3
@@ -29,7 +29,7 @@ async def announcer(bot, announcement):
|
|||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
async def rename_vc(bot: discord.Bot):
|
async def rename_vc(bot: discord.Bot, from_scheduler: bool = False):
|
||||||
global current, train_name, train_info, train_type, _scheduled_task
|
global current, train_name, train_info, train_type, _scheduled_task
|
||||||
|
|
||||||
guild = bot.get_guild(int(config["server"]))
|
guild = bot.get_guild(int(config["server"]))
|
||||||
@@ -42,6 +42,9 @@ async def rename_vc(bot: discord.Bot):
|
|||||||
logger(f"Es konnte kein VC mit der ID {config['vc']} auf dem Server gefunden werden", "fatal")
|
logger(f"Es konnte kein VC mit der ID {config['vc']} auf dem Server gefunden werden", "fatal")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
if not from_scheduler and _scheduled_task and not _scheduled_task.done():
|
||||||
|
_scheduled_task.cancel()
|
||||||
|
|
||||||
attempt = 0
|
attempt = 0
|
||||||
while True:
|
while True:
|
||||||
if attempt == 20:
|
if attempt == 20:
|
||||||
@@ -75,7 +78,6 @@ async def rename_vc(bot: discord.Bot):
|
|||||||
arrival = datetime.fromisoformat((train_info["arrival"]))
|
arrival = datetime.fromisoformat((train_info["arrival"]))
|
||||||
formatting = get_channel_formatting(train_type)
|
formatting = get_channel_formatting(train_type)
|
||||||
|
|
||||||
_scheduled_task = asyncio.create_task(_schedule_next_umstieg(bot, arrival))
|
|
||||||
|
|
||||||
print("-----------------------------------------")
|
print("-----------------------------------------")
|
||||||
logger(f"Umstieg: {train_name}")
|
logger(f"Umstieg: {train_name}")
|
||||||
@@ -89,6 +91,8 @@ async def rename_vc(bot: discord.Bot):
|
|||||||
if config.get("announcements", True):
|
if config.get("announcements", True):
|
||||||
await announcer(bot, "umstieg")
|
await announcer(bot, "umstieg")
|
||||||
|
|
||||||
|
_scheduled_task = asyncio.create_task(_schedule_next_umstieg(bot, arrival))
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
async def _schedule_next_umstieg(bot, arrival):
|
async def _schedule_next_umstieg(bot, arrival):
|
||||||
@@ -109,4 +113,4 @@ async def _schedule_next_umstieg(bot, arrival):
|
|||||||
await asyncio.sleep(wait_seconds)
|
await asyncio.sleep(wait_seconds)
|
||||||
|
|
||||||
logger("Zug angekommen, wähle neue Verbindung...")
|
logger("Zug angekommen, wähle neue Verbindung...")
|
||||||
await rename_vc(bot)
|
await rename_vc(bot, from_scheduler=True)
|
||||||
Reference in New Issue
Block a user