From fc4aa59f5c5ba0baf10681d4db9d4d7c722f3583 Mon Sep 17 00:00:00 2001 From: ducklet Date: Mon, 16 Nov 2020 21:09:15 +0100 Subject: [PATCH] feed: fix only the last configured feed being updated We need to properly capture the feed-id for the callback function. Defining the function inside the loop (even when copying feed.id into a separate var beforehand) will not do this and will instead end up being the same feed-id for all callback functions. --- hotdog/command/feed.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/hotdog/command/feed.py b/hotdog/command/feed.py index 4535dce..e624a57 100644 --- a/hotdog/command/feed.py +++ b/hotdog/command/feed.py @@ -30,6 +30,13 @@ def make_filter(config: Mapping[str, str]) -> Callable[[feeder.Post], bool]: return filter +def make_update_feed_cb(feed_id): + async def update_feed_cb(job: Job): + await update_feeds([feed_id], job) + + return update_feed_cb + + def init(bot): bot.on_command("feed", handle) @@ -63,13 +70,10 @@ def init(bot): every_period = feedconf.get(feed.id, {}).get("update_every") every_s = parse_period(every_period) if every_period else one_hour - async def update_feed_cb(job: Job): - await update_feeds([feed.id], job) - bot.add_timer( title=f"update feed: {feed.id}", every=every_s, - callback=update_feed_cb, + callback=make_update_feed_cb(feed.id), jitter=ten_percent * every_s, )