summaryrefslogtreecommitdiffstats
path: root/askbot/tasks.py
diff options
context:
space:
mode:
authorEvgeny Fadeev <evgeny.fadeev@gmail.com>2011-04-08 18:20:58 -0400
committerEvgeny Fadeev <evgeny.fadeev@gmail.com>2011-04-08 18:20:58 -0400
commit0466f4cab19f4723314aff18b92c353561dc6c2b (patch)
tree478b67384aea50a049ce956bada508a3515ae723 /askbot/tasks.py
parent0298c14ae7ee124b80b147b8801145777bbdf712 (diff)
downloadaskbot-0466f4cab19f4723314aff18b92c353561dc6c2b.tar.gz
askbot-0466f4cab19f4723314aff18b92c353561dc6c2b.tar.bz2
askbot-0466f4cab19f4723314aff18b92c353561dc6c2b.zip
commented the email subscription code and made a change that caused issue with the test case to disappear - not sure why it helped...
Diffstat (limited to 'askbot/tasks.py')
-rw-r--r--askbot/tasks.py59
1 files changed, 53 insertions, 6 deletions
diff --git a/askbot/tasks.py b/askbot/tasks.py
index e230be31..8dfea5b4 100644
--- a/askbot/tasks.py
+++ b/askbot/tasks.py
@@ -1,3 +1,22 @@
+"""Definitions of Celery tasks in Askbot
+in this module there are two types of functions:
+
+* those wrapped with a @task decorator and a ``_celery_task`` suffix - celery tasks
+* those with the same base name, but without the decorator and the name suffix
+ the actual work units run by the task
+
+Celery tasks are special functions in a way that they require all the parameters
+be serializable - so instead of ORM objects we pass object id's and
+instead of query sets - lists of ORM object id's.
+
+That is the reason for having two types of methods here:
+
+* the base methods (those without the decorator and the
+ ``_celery_task`` in the end of the name
+ are work units that are called from the celery tasks.
+* celery tasks - shells that reconstitute the necessary ORM
+ objects and call the base methods
+"""
from django.contrib.contenttypes.models import ContentType
from celery.decorators import task
from askbot.models import Activity
@@ -5,7 +24,7 @@ from askbot.models import User
from askbot.models import send_instant_notifications_about_activity_in_post
@task(ignore_results = True)
-def record_post_update_task(
+def record_post_update_celery_task(
post_id,
post_content_type_id,
newly_mentioned_user_id_list = None,
@@ -13,10 +32,42 @@ def record_post_update_task(
timestamp = None,
created = False,
):
-
+ #reconstitute objects from the database
updated_by = User.objects.get(id = updated_by_id)
post_content_type = ContentType.objects.get(id = post_content_type_id)
post = post_content_type.get_object_for_this_type(id = post_id)
+ newly_mentioned_users = User.objects.filter(
+ id__in = newly_mentioned_user_id_list
+ )
+
+
+ record_post_update(
+ post = post,
+ updated_by = updated_by,
+ newly_mentioned_users = newly_mentioned_users,
+ timestamp = timestamp,
+ created = created,
+ )
+
+def record_post_update(
+ post = None,
+ updated_by = None,
+ newly_mentioned_users = None,
+ timestamp = None,
+ created = False
+ ):
+ """Called when a post is updated. Arguments:
+
+ * ``newly_mentioned_users`` - users who are mentioned in the
+ post for the first time
+ * ``created`` - a boolean. True when ``post`` has just been created
+ * remaining arguments are self - explanatory
+
+ The method does two things:
+
+ * records "red envelope" recipients of the post
+ * sends email alerts to all subscribers to the post
+ """
#todo: take into account created == True case
(activity_type, update_object) = post.get_updated_activity_data(created)
@@ -42,10 +93,6 @@ def record_post_update_task(
assert(updated_by not in recipients)
- newly_mentioned_users = User.objects.filter(
- id__in = newly_mentioned_user_id_list
- )
-
for user in set(recipients) | set(newly_mentioned_users):
user.increment_response_count()
user.save()