Skip to content

Commit

Permalink
Hotfix: Fixed 503 on HTTP caused by missing new params
Browse files Browse the repository at this point in the history
  • Loading branch information
blackandred committed Jun 28, 2019
1 parent 9b6b8af commit 48d42f6
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 13 deletions.
2 changes: 2 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
CHANGES
=======

* Updated suggestion in reference in docs
* Added --lazy flag
* Added --wait / WAIT\_TIME, secured \`domain-expiration\` check against CPU overload
* Added docs, clean up
* Resolved unit tests
Expand Down
3 changes: 2 additions & 1 deletion infracheck/infracheck/bin.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ def main():
server_port = int(parsed.server_port if parsed.server_port else 7422)
server_path_prefix = parsed.server_path_prefix if parsed.server_path_prefix else ''

app = Controller(project_dir, server_port, server_path_prefix, parsed.db_path)
app = Controller(project_dir, server_port, server_path_prefix,
parsed.db_path, parsed.wait, parsed.lazy, parsed.force)

if parsed.server:
app.spawn_server()
Expand Down
16 changes: 9 additions & 7 deletions infracheck/infracheck/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ class Controller:
config_loader = None # type: ConfigLoader
server = None # type: HttpServer

def __init__(self, project_dir: str, server_port: int, server_path_prefix: str, db_path: str):
def __init__(self, project_dir: str, server_port: int, server_path_prefix: str,
db_path: str, wait_time: int, lazy: bool, force: bool):

self.project_dirs = self._combine_project_dirs(project_dir)
self.runner = Runner(self.project_dirs)
self.config_loader = ConfigLoader(self.project_dirs)
self.repository = Repository(self.project_dirs, db_path)
self.server = HttpServer(self, server_port, server_path_prefix)
self.server = HttpServer(self, server_port, server_path_prefix, wait_time, lazy, force)

def list_enabled_configs(self):
return self.repository.get_configured_checks(with_disabled=False)
Expand Down Expand Up @@ -58,11 +60,11 @@ def perform_checks(self, force: bool, wait_time: int = 0, lazy=False):
config = self.config_loader.load(config_name)

if not result:
result = self.runner.run(config['type'], config['input'], config.get('hooks', {})) \
if lazy else ["Check not ready", False, ""]

# store in the cache
self.repository.push_to_cache(config_name, result)
if lazy:
result = self.runner.run(config['type'], config['input'], config.get('hooks', {}))
self.repository.push_to_cache(config_name, result)
else:
result = ["Check not ready", False, ""]

results[config_name] = {
'status': result[1],
Expand Down
20 changes: 16 additions & 4 deletions infracheck/infracheck/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@

class MainHandler(tornado.web.RequestHandler): # pragma: no cover
app = None
wait_time = 0
lazy = False
force = False

def get(self):
result = self.app.perform_checks()
result = self.app.perform_checks(force=self.force, wait_time=self.wait_time, lazy=self.lazy)
self.set_status(500 if not result['global_status'] else 200)
self.add_header('Content-Type', 'application/json')
self.write(
Expand All @@ -21,16 +24,25 @@ def data_received(self, chunk):

class HttpServer:
app = None
port = 7422
path_prefix = ''
port: int
path_prefix: str
wait_time: int
lazy: bool
force: bool

def __init__(self, app, port: int, server_path_prefix: str):
def __init__(self, app, port: int, server_path_prefix: str, wait_time: int, lazy: bool, force: bool):
self.app = app
self.port = port
self.path_prefix = server_path_prefix
self.wait_time = wait_time
self.lazy = lazy
self.force = force

def run(self):
MainHandler.app = self.app
MainHandler.wait_time = self.wait_time
MainHandler.lazy = self.lazy
MainHandler.force = self.force

srv = tornado.web.Application([(r"" + self.path_prefix + "/", MainHandler)])
srv.listen(self.port)
Expand Down
5 changes: 4 additions & 1 deletion tests/test_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,10 @@ def test_simply_perform_checks(self, config: dict, expected_result: bool, expect
project_dir=path,
server_port=8000,
server_path_prefix='',
db_path='/tmp/.infracheck.sqlite3'
db_path='/tmp/.infracheck.sqlite3',
wait_time=0,
lazy=True,
force=True
)

# mocks
Expand Down

0 comments on commit 48d42f6

Please sign in to comment.