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
Matt Dietz
committed
Apr 1, 2011
1 parent
8d9f52f
commit f9ee679
Showing
23 changed files
with
355 additions
and
95 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.pyc |
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,4 +1,27 @@ | ||
Dependencies: | ||
# Yagi | ||
|
||
feedgenerator | ||
carrot (if using Rabbit) | ||
A PubSubHubBub Publisher implementation in Python | ||
|
||
## Why PubSubHubBub? | ||
|
||
We wanted to use a defined spec with easy to use clients, and PubSubHubBub fit | ||
the bill nicely. | ||
|
||
## Why implement an external publisher? | ||
|
||
The original impetus for this project is to adapt an existing piece of | ||
software to sending notifications without laying the job of managing those | ||
notifications on said implementation. Because PubSubHubBub requires an ATOM | ||
feed, we didn\'t want the original software from having to worry about | ||
completely unrelated functionality. Additionally, this route buys us a | ||
lot of flexibility. | ||
|
||
## Dependencies: | ||
|
||
* feedgenerator | ||
* redis | ||
* webob | ||
* eventlet | ||
* daemon | ||
* pubsubhubbub_publish (available under the publisher_clients folder after checking out the project from [Google Code](http://code.google.com/p/pubsubhubbub/source/checkout) | ||
* carrot (if using Rabbit) |
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,23 @@ | ||
#!/usr/bin/python | ||
import os | ||
import sys | ||
import unittest | ||
|
||
import daemon | ||
import nose | ||
import nose.config | ||
import nose.core | ||
|
||
possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), | ||
os.pardir, | ||
os.pardir)) | ||
if os.path.exists(os.path.join(possible_topdir, 'yagi', '__init__.py')): | ||
sys.path.insert(0, possible_topdir) | ||
|
||
if __name__ == '__main__': | ||
test_path = os.path.abspath(os.path.join('tests', 'unit')) | ||
c = nose.config.Config(stream=sys.stdout, | ||
env=os.environ, | ||
verbosity=3, | ||
workingDir=test_path) | ||
nose.core.run(config=c, argv=sys.argv) |
File renamed without changes.
Empty file.
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,25 @@ | ||
import unittest | ||
|
||
import stubout | ||
|
||
import yagi.config | ||
import yagi.serializer | ||
|
||
class SerializerTests(unittest.TestCase): | ||
def setUp(self): | ||
self.stubs = stubout.StubOutForTesting() | ||
|
||
def tearDown(self): | ||
self.stubs.UnsetAll() | ||
|
||
def test_load_serializer(self): | ||
"""Contrived test for basic functionality""" | ||
|
||
def config_get(*args, **kwargs): | ||
return 'yagi.serializer.atom' | ||
|
||
yagi.config.get() | ||
self.stubs.Set(yagi.config, 'get', config_get) | ||
|
||
ser = yagi.serializer.feed_serializer() | ||
self.assertEqual(ser, yagi.serializer.atom) |
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 |
---|---|---|
@@ -1 +0,0 @@ | ||
|
||
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,10 +1,34 @@ | ||
import json | ||
import time | ||
|
||
import yagi.log | ||
|
||
LOG = yagi.log.logger | ||
|
||
|
||
class Message(object): | ||
def ack(self): | ||
pass | ||
|
||
|
||
class Broker(object): | ||
"""A flimsy class for testing the event worker""" | ||
def __init__(self): | ||
pass | ||
self.pipe = open('queue.fifo', 'r') | ||
self.callback = None | ||
|
||
def register_callback(self, fun): | ||
pass | ||
self.callback = fun | ||
|
||
def loop(self): | ||
pass | ||
|
||
while True: | ||
time.sleep(2) | ||
try: | ||
line = self.pipe.readline() | ||
if len(line) > 0: | ||
LOG.debug('Got %s' % line) | ||
line = json.loads(line) | ||
message = Message() | ||
self.callback(line['msg'], message) | ||
except Exception, e: | ||
LOG.debug(e) |
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 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,21 +1,38 @@ | ||
import json | ||
|
||
import yagi.config | ||
import yagi.log | ||
import yagi.notifier | ||
import yagi.persistence | ||
import yagi.utils | ||
|
||
LOG = yagi.log.logger | ||
|
||
|
||
class EventWorker(object): | ||
def __init__(self): | ||
self.broker = yagi.utils.import_class(yagi.config.get('event_worker', | ||
'event_driver'))() | ||
self.db = yagi.persistence.persistence_driver() | ||
|
||
def fetched_message(self, message_data, message_topic): | ||
LOG.debug('Got message %s %s' % (message_data, message_topic)) | ||
def fetched_message(self, message_data, message): | ||
LOG.debug('Received %s' % (message_data)) | ||
try: | ||
obj = json.loads(message_data) | ||
self.db.create(obj['key'], json.dumps(obj['content'])) | ||
LOG.debug('New notification created') | ||
yagi.notifier.notify(yagi.utils.topic_url(obj['key'])) | ||
except Exception, e: | ||
LOG.debug(e) | ||
finally: | ||
message.ack() | ||
|
||
def start(self): | ||
LOG.debug('Starting eventworker...') | ||
self.broker.register_callback(self.fetched_message) | ||
self.broker.loop() | ||
|
||
|
||
|
||
def start(): | ||
event_worker = EventWorker() | ||
event_worker.start() |
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 +0,0 @@ | ||
|
||
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
Oops, something went wrong.