Skip to content

Commit

Permalink
Fix integrations
Browse files Browse the repository at this point in the history
  • Loading branch information
stewartpark committed Feb 7, 2017
1 parent 8653a29 commit 98e4d5b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 24 deletions.
2 changes: 1 addition & 1 deletion fdep/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__VERSION__ = '0.2.2'
__VERSION__ = '0.2.3'
58 changes: 36 additions & 22 deletions fdep/commands/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,33 +94,47 @@ def run(self, *args, **kwargs):
kwargs['username'] = username
kwargs['password'] = password

# Ensure everything is installed safe and sound.
if not self.root_runner.commands['install'].run():
return False

func_pairs = self.get_func_pairs(python_module_name)
if server_driver_name in self.__class__.KNOWN_DRIVERS:
server_driver = self.__class__.KNOWN_DRIVERS[server_driver_name]
else:
# User-provided driver
server_driver = self.resolve_module(server_driver_name)

integrations = []
sentry_dsn = kwargs.get('sentry_dsn') or os.environ.get('SENTRY_DSN')
sentry_integration = None
if sentry_dsn:
try:
integrations.append(SentryIntegration(sentry_dsn))
sentry_integration = SentryIntegration(sentry_dsn)
except ImportError:
sys.stderr.write(
self.messages.ERROR_NEED_TO_INSTALL_OPTIONAL.format('raven', 'Sentry')
)
fluentd_http_url = kwargs.get('fluentd_http_url') or os.environ.get('FLUENTD_HTTP_URL')
if fluentd_http_url:
integrations.append(FluentdHttpIntegration(fluentd_http_url))

if server_driver_name != 'console':
print(self.messages.SERVING.format(server_driver_name, python_module_name, port))

server = server_driver()
server.register_functions(func_pairs)
server.serve_forever(**kwargs)
try:
# Ensure everything is installed safe and sound.
if not self.root_runner.commands['install'].run():
return False

func_pairs = self.get_func_pairs(python_module_name)
if server_driver_name in self.__class__.KNOWN_DRIVERS:
server_driver = self.__class__.KNOWN_DRIVERS[server_driver_name]
else:
# User-provided driver
server_driver_path, server_driver_class = server_driver_name.rsplit('.', 1)
server_driver_module = self.resolve_module(server_driver_path)
server_driver = getattr(server_driver_module, server_driver_class)

integrations = []

if sentry_integration is not None:
integrations.append(sentry_integration)

fluentd_http_url = kwargs.get('fluentd_http_url') or os.environ.get('FLUENTD_HTTP_URL')
if fluentd_http_url:
integrations.append(FluentdHttpIntegration(fluentd_http_url))

if server_driver_name != 'console':
print(self.messages.SERVING.format(server_driver_name, python_module_name, port))

server = server_driver()
server.register_integrations(integrations)
server.register_functions(func_pairs)
server.serve_forever(**kwargs)
except Exception as e:
if sentry_integration is not None:
sentry_integration.capture_exception(e)
raise
2 changes: 1 addition & 1 deletion fdep/servers/integrations/fluentd_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ def after_function(self, func_name, args, kwargs, result):
})
).status_code
if status_code >= 400:
sys.stderr.write("Fluentd transmission failed")
sys.stderr.write("Fluentd transmission failed.\n")

0 comments on commit 98e4d5b

Please sign in to comment.