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.
This commit is contained in:
parent
124ed1cf25
commit
fc4aa59f5c
1 changed files with 8 additions and 4 deletions
|
|
@ -30,6 +30,13 @@ def make_filter(config: Mapping[str, str]) -> Callable[[feeder.Post], bool]:
|
||||||
return filter
|
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):
|
def init(bot):
|
||||||
bot.on_command("feed", handle)
|
bot.on_command("feed", handle)
|
||||||
|
|
||||||
|
|
@ -63,13 +70,10 @@ def init(bot):
|
||||||
every_period = feedconf.get(feed.id, {}).get("update_every")
|
every_period = feedconf.get(feed.id, {}).get("update_every")
|
||||||
every_s = parse_period(every_period) if every_period else one_hour
|
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(
|
bot.add_timer(
|
||||||
title=f"update feed: {feed.id}",
|
title=f"update feed: {feed.id}",
|
||||||
every=every_s,
|
every=every_s,
|
||||||
callback=update_feed_cb,
|
callback=make_update_feed_cb(feed.id),
|
||||||
jitter=ten_percent * every_s,
|
jitter=ten_percent * every_s,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue