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

documentation on making own checks #146

Closed
tisdall opened this issue Sep 5, 2019 · 2 comments
Closed

documentation on making own checks #146

tisdall opened this issue Sep 5, 2019 · 2 comments

Comments

@tisdall
Copy link
Contributor

tisdall commented Sep 5, 2019

It's been a while since I've touched this stuff and I'm having some issues with custom checks. The docs have one example that seems to give an exception:

from watchman.decorators import check

@check
def my_check():
    return {'x': 1}
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner
    response = get_response(request)
  File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py", line 115, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py", line 113, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/usr/local/lib/python3.6/contextlib.py", line 52, in inner
    return func(*args, **kwds)
  File "/usr/local/lib/python3.6/contextlib.py", line 52, in inner
    return func(*args, **kwds)
  File "/usr/local/lib/python3.6/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/watchman/decorators.py", line 107, in _wrapped_view
    return view_func(request, *args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/watchman/views.py", line 163, in dashboard
    for outer_status in value:
TypeError: 'int' object is not iterable

It seems that it should be instead this:

from watchman.decorators import check

@check
def my_check():
    return {'my_check': {'ok': True}}

There's also an exception if the 'ok' key is missing.

This is using Django 2.2.4 on python 3.6.7

@stale
Copy link

stale bot commented Nov 4, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Nov 4, 2019
@stale stale bot removed the stale label Nov 4, 2019
@mwarkentin
Copy link
Owner

@tisdall in an amazingly slow response, this came up again in #188. I've updated the docs and sample project with the current way to write custom checks:

You currently need to wrap the check in another function in order to provide the proper response structure on both exceptions and ok status:

def fail_custom_check():
    return {"fail_custom_check": _fail_custom_check()}


@check
def _fail_custom_check():
    raise Exception("The answer is 42")


def ok_custom_check():
    return {"ok_custom_check": _ok_custom_check()}


@check
def _ok_custom_check():
    return {"ok": True}

I've opened #191 for an improvement to the decorator which would allow it to work as the top level function call.

Going to close this one off now.. thanks for reporting it initially!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants