From e8f8885f22e2ec0a79c7404de86e3d693e941c0b Mon Sep 17 00:00:00 2001 From: Deimos Date: Tue, 26 May 2020 18:48:40 -0600 Subject: [PATCH] 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. --- tildes/scripts/post_scheduled_topics.py | 2 +- tildes/tildes/models/topic/topic_schedule.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tildes/scripts/post_scheduled_topics.py b/tildes/scripts/post_scheduled_topics.py index ef0dce4..3dab4e5 100644 --- a/tildes/scripts/post_scheduled_topics.py +++ b/tildes/scripts/post_scheduled_topics.py @@ -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() diff --git a/tildes/tildes/models/topic/topic_schedule.py b/tildes/tildes/models/topic/topic_schedule.py index ab74b60..89a0f58 100644 --- a/tildes/tildes/models/topic/topic_schedule.py +++ b/tildes/tildes/models/topic/topic_schedule.py @@ -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