Skip to content

Commit

Permalink
adding warning when timeout is greater than 300
Browse files Browse the repository at this point in the history
moving validation to load_settings

validate timeout_seconds

make sure module exists
  • Loading branch information
doron2402 committed Jul 12, 2017
1 parent fa0e3cd commit b06b6df
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions zappa/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1843,6 +1843,30 @@ def load_settings(self, settings_file=None, session=None):
# Load up file
self.load_settings_file(settings_file)

# Validate settings
# Validate timeout seconds
if self.stage_config.get('timeout_seconds') > 300 or self.stage_config.get('timeout_seconds') < 1:
click.echo(click.style("Warning!", fg="red", bold=True) + "`timeout_seconds` must be greater than 1 and less or equal to 300 !"

# Validate file & handler function
if self.app_function is None:
click.echo(click.style("Warning!", fg="red", bold=True) +
" Your app_function None, make sure app_function is pointing to a " + click.style("file and not a function", bold=True)
else:
self.collision_warning(self.app_function)
if self.app_function[-3:] == '.py':
click.echo(click.style("Warning!", fg="red", bold=True) +
" Your app_function is pointing to a " + click.style("file and not a function", bold=True) +
"! It should probably be something like 'my_file.app', not 'my_file.py'!")
if '.' not in self.app_function: # pragma: no cover
raise ClickException("Your " + click.style("app_function", fg='red', bold=True) + " value is not a modular path." +
" It needs to be in the format `" + click.style("your_module.your_app_object", bold=True) + "`.")

app_module, app_function = self.app_function.rsplit('.', 1)
if os.path.isfile(app_module + ".py") is False:
raise ClickException("Your " + click.style("app_function", fg='red', bold=True) + " value is non exsiting file" +
" make sure the file is in the same directory and named " + click.style(app_module + ".py", bold=True))

# Make sure that the stages are valid names:
for stage_name in self.zappa_settings.keys():
try:
Expand Down Expand Up @@ -1932,13 +1956,6 @@ def load_settings(self, settings_file=None, session=None):
setting_val = f.read()
setattr(self.zappa, setting, setting_val)

if self.app_function:
self.collision_warning(self.app_function)
if self.app_function[-3:] == '.py':
click.echo(click.style("Warning!", fg="red", bold=True) +
" Your app_function is pointing to a " + click.style("file and not a function", bold=True) +
"! It should probably be something like 'my_file.app', not 'my_file.py'!")

return self.zappa

def get_json_or_yaml_settings(self, settings_name="zappa_settings"):
Expand Down Expand Up @@ -2087,9 +2104,6 @@ def create_package(self, output=None):
settings_s = "# Generated by Zappa\n"

if self.app_function:
if '.' not in self.app_function: # pragma: no cover
raise ClickException("Your " + click.style("app_function", fg='red', bold=True) + " value is not a modular path." +
" It needs to be in the format `" + click.style("your_module.your_app_object", bold=True) + "`.")
app_module, app_function = self.app_function.rsplit('.', 1)
settings_s = settings_s + "APP_MODULE='{0!s}'\nAPP_FUNCTION='{1!s}'\n".format(app_module, app_function)

Expand Down

0 comments on commit b06b6df

Please sign in to comment.