[History] refactor inserting history entries
[mygpo.git] / mygpo / directory / tasks.py
blobcf8d10a6bfa9cf7cf241f77fa5462b7f253f3bc9
1 from mygpo.podcasts.models import Podcast
2 from mygpo.subscriptions.models import Subscription
3 from mygpo.celery import celery
6 @celery.task(max_retries=5)
7 def update_podcast_subscribers(podcast_id):
8 """ Updates the subscriber count of a podcast """
10 try:
11 podcast = Podcast.objects.get(id=podcast_id)
13 # calculate current number of subscribers
14 podcast.subscribers = Subscription.objects.filter(podcast=podcast)\
15 .order_by('user')\
16 .distinct('user')\
17 .count()
18 podcast.save()
20 #TODO: which exceptions?
21 except Exception as ex:
22 raise update_podcast_subscribers.retry(exc=ex)