forked from localstack/localstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merged in feat/refactor-kinesis-utils (pull request localstack#25)
Refactoring: move kinesis utils to separate file
- Loading branch information
Showing
5 changed files
with
57 additions
and
46 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
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,51 @@ | ||
import json | ||
import socket | ||
import traceback | ||
import logging | ||
from localstack.utils.common import FuncThread | ||
|
||
# set up local logger | ||
LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
class EventFileReaderThread(FuncThread): | ||
def __init__(self, events_file, callback, ready_mutex=None): | ||
FuncThread.__init__(self, self.retrieve_loop, None) | ||
self.running = True | ||
self.events_file = events_file | ||
self.callback = callback | ||
self.ready_mutex = ready_mutex | ||
|
||
def retrieve_loop(self, params): | ||
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) | ||
sock.bind(self.events_file) | ||
sock.listen(1) | ||
if self.ready_mutex: | ||
self.ready_mutex.release() | ||
while self.running: | ||
try: | ||
conn, client_addr = sock.accept() | ||
thread = FuncThread(self.handle_connection, conn) | ||
thread.start() | ||
except Exception, e: | ||
LOGGER.error('Error dispatching client request: %s %s' % (e, traceback.format_exc())) | ||
sock.close() | ||
|
||
def handle_connection(self, conn): | ||
socket_file = conn.makefile() | ||
while self.running: | ||
line = socket_file.readline()[:-1] | ||
if line == '': | ||
# end of socket input stream | ||
break | ||
else: | ||
try: | ||
records = json.loads(line) | ||
self.callback(records) | ||
except Exception, e: | ||
LOGGER.warning("Unable to process JSON line: '%s': %s. Callback: %s" % | ||
(truncate(line), traceback.format_exc(), self.callback)) | ||
conn.close() | ||
|
||
def stop(self, quiet=True): | ||
self.running = False |
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 |
---|---|---|
|
@@ -76,7 +76,7 @@ def run(self): | |
|
||
setup( | ||
name='localstack', | ||
version='0.1.15', | ||
version='0.1.16', | ||
description='Provides an easy-to-use test/mocking framework for developing Cloud applications', | ||
author='Waldemar Hummer (Atlassian)', | ||
author_email='[email protected]', | ||
|