mirror of
https://gitlab.com/tildes/tildes.git
synced 2026-04-17 06:48:36 +02:00
Don't post full "backlog" of scheduled topics
This will probably only ever be relevant in development environments, but we don't want the topic scheduler to always post a full backlog of scheduled topics when it hasn't run for a while. For example, if a dev environment has a daily scheduled topic set up, but the VM is not launched for a week, the next time the "post scheduled topics" cronjob runs, it will post all 7 of the backlogged topics. This commit changes the script so that it advances the schedule to the next *future* occurrence, instead of continuing the backlog.
This commit is contained in:
@@ -36,7 +36,7 @@ def post_scheduled_topics(config_path: str) -> None:
|
||||
|
||||
while due_topic:
|
||||
db_session.add(due_topic.create_topic())
|
||||
due_topic.advance_schedule()
|
||||
due_topic.advance_schedule_to_future()
|
||||
db_session.add(due_topic)
|
||||
db_session.commit()
|
||||
|
||||
|
||||
@@ -106,10 +106,10 @@ class TopicSchedule(DatabaseModel):
|
||||
|
||||
return topic
|
||||
|
||||
def advance_schedule(self) -> None:
|
||||
"""Advance the schedule, setting next_post_time appropriately."""
|
||||
def advance_schedule_to_future(self) -> None:
|
||||
"""Advance the schedule to the next future occurrence."""
|
||||
if self.recurrence_rule:
|
||||
rule = self.recurrence_rule.replace(dtstart=self.next_post_time)
|
||||
self.next_post_time = rule.after(self.next_post_time)
|
||||
self.next_post_time = rule.after(utc_now())
|
||||
else:
|
||||
self.next_post_time = None
|
||||
|
||||
Reference in New Issue
Block a user