Skip to content

Commit

Permalink
fix(component): update component alerts hourly
Browse files Browse the repository at this point in the history
This avoids too long task execution on large sites.

Fixes WEBLATE-FB
  • Loading branch information
nijel committed Jun 19, 2024
1 parent 80742ec commit cbe8906
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions weblate/trans/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,10 @@ def component_alerts(component_ids=None) -> None:
if component_ids:
components = Component.objects.filter(pk__in=component_ids)
else:
components = Component.objects.all()
now = timezone.now()
components = Component.objects.annotate(hourmod=F("id") % 24).filter(
hourmod=now.hour
)
for component in components.prefetch():
with transaction.atomic():
component.update_alerts()
Expand Down Expand Up @@ -708,9 +711,7 @@ def setup_periodic_tasks(sender, **kwargs) -> None:
sender.add_periodic_task(
crontab(hour=3, minute=45), repository_alerts.s(), name="repository-alerts"
)
sender.add_periodic_task(
crontab(hour=3, minute=55), component_alerts.s(), name="component-alerts"
)
sender.add_periodic_task(3600, component_alerts.s(), name="component-alerts")
sender.add_periodic_task(
crontab(hour=0, minute=40), cleanup_suggestions.s(), name="suggestions-cleanup"
)
Expand Down

0 comments on commit cbe8906

Please sign in to comment.