Browse Source

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.
merge-requests/110/head
Deimos 5 years ago
parent
commit
e8f8885f22
  1. 2
      tildes/scripts/post_scheduled_topics.py
  2. 6
      tildes/tildes/models/topic/topic_schedule.py

2
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()

6
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
Loading…
Cancel
Save