-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
aaron morton
authored and
aaron morton
committed
Jul 27, 2012
1 parent
b264ee0
commit 044b294
Showing
10 changed files
with
297 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Use redis as the message broker. | ||
BROKER_URL = "redis://localhost:6379/0" | ||
|
||
# This is the task status stored. | ||
# Want to change to cassandra later | ||
|
||
CELERY_RESULT_BACKEND = "redis" | ||
CELERY_REDIS_HOST = "localhost" | ||
CELERY_REDIS_PORT = 6379 | ||
CELERY_REDIS_DB = 0 | ||
|
||
CELERYD_LOG_FORMAT="%(asctime)s - %(processName)s - %(name)s - %(lineno)d - %(levelname)s - %(message)s" | ||
|
||
# This tells the celery worker server to look in tasks.py for tasks | ||
CELERY_IMPORTS = ("wdcnz.tasks", ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
tornado>=2.2.1 | ||
pycassa>=1.6.0 | ||
Mako>=0.7.0 | ||
Mako>=0.7.0 | ||
celery-with-redis>=2.4.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
"""Just put all the smarts in here""" | ||
|
||
import logging | ||
|
||
import celery | ||
|
||
import pycassa | ||
from pycassa.cassandra import ttypes as cass_types | ||
|
||
|
||
@celery.task() | ||
def deliver_tweet(from_user, tweet_id, tweet_json): | ||
"""Delivers the tweet with ``tweet_id`` to ``from_user``'s followers. | ||
""" | ||
|
||
pool = get_cass_pool() | ||
followers_cf = column_family(pool, "OrderedFollowers") | ||
user_timeline_cf = column_family(pool, "UserTimeline") | ||
|
||
with pycassa.batch.Mutator(pool, queue_size=50) as batch: | ||
batch.write_consistency_level = cass_types.ConsistencyLevel.QUORUM | ||
|
||
columns = { | ||
tweet_id : tweet_json | ||
} | ||
|
||
followers_row_key = from_user | ||
for col_name, _ in followers_cf.get(followers_row_key).iteritems(): | ||
# col name is (timestamp, user_name) | ||
_, follower_user_name = col_name | ||
|
||
# Insert tweet into UserTimeline CF | ||
row_key = follower_user_name | ||
batch.insert(user_timeline_cf, row_key, columns) | ||
|
||
return | ||
|
||
|
||
# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
# Helpers | ||
|
||
def get_cass_pool(): | ||
return pycassa.ConnectionPool("wdcnz", ["localhost:9160"]) | ||
|
||
def column_family(cass_pool, name): | ||
return pycassa.ColumnFamily(cass_pool, name, | ||
read_consistency_level=cass_types.ConsistencyLevel.QUORUM, | ||
write_consistency_level=cass_types.ConsistencyLevel.QUORUM) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.