Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lazy connections #2

Merged
merged 2 commits into from Aug 5, 2016
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -0,0 +1 @@
__version__ = '1.0.1'
@@ -1,7 +1,6 @@
"""
" Copyright: Loggly
" Author: Scott Griffin
" Last Updated: 02/22/2013
"
"""
try: import simplejson as json
@@ -83,12 +82,25 @@ class S3Producer( BaseProducer ):

def __init__(self, **kwargs):
super( S3Producer, self ).__init__(**kwargs)
self.s3conn = boto.connect_s3( self.config.s3_key, self.config.s3_secret )

self.bucket = self.s3conn.lookup( self.config.s3_bucket )
self._s3conn = None
self._bucket = None

@property
def s3conn(self):
if self._s3conn is None:
self._s3conn = boto.connect_s3( self.config.s3_key, self.config.s3_secret )
return self._s3conn

@property
def bucket(self):
if self._bucket is None:
self._bucket = self.s3conn.lookup( self.config.s3_bucket )

if not self.bucket:
self.bucket = self.s3conn.create_bucket( self.config.s3_bucket )
if not self._bucket:
self._bucket = self.s3conn.create_bucket( self.config.s3_bucket )

return self._bucket


def send( self, msg, **kwargs ):
"""
@@ -1,7 +1,6 @@
"""
" Copyright: Loggly
" Author: Scott Griffin
" Last Updated: 02/22/2013
"
" This class provides the ability to register a function as
" a consumer to an S3 routing_key. This class also handles tracking
@@ -74,8 +73,8 @@ class S3Consumer(object):
def __init__(self, routing_key, func, name=None, config='config.py'):

self.config = config_loader( config )
self.s3conn = boto.connect_s3( self.config.s3_key, self.config.s3_secret )
self.bucket = self.s3conn.get_bucket( self.config.s3_bucket )
self._s3conn = None
self._bucket = None
self.routing_key = routing_key.upper()
self.callback = func

@@ -90,6 +89,18 @@ def __init__(self, routing_key, func, name=None, config='config.py'):
location=self.config.s3_cursor['location']
)


@property
def s3conn(self):
if self._s3conn is None:
self._s3conn = boto.connect_s3( self.config.s3_key, self.config.s3_secret )
return self._s3conn

@property
def bucket(self):
if self._bucket is None:
self._bucket = self.s3conn.get_bucket( self.config.s3_bucket )
return self._bucket

def _gen_name(self, func):
""" Generates a cursor name so that the cursor can be re-attached to """
@@ -1,16 +1,16 @@
"""
" Copyright: Loggly
" Author: Scott Griffin
" Last Updated: 01/14/2013
"
"""
from setuptools import setup
from muskrat import __version__

setup(
name='Muskrat',
author='Scott Griffin',
author_email='scott@loggly.com',
version='0.1dev',
version=__version__,
packages=['muskrat', 'muskrat.tests'],
long_description=open( 'README.md' ).read(),
install_requires=open( 'requirements.txt' ).read().split()
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.