diff --git a/docs/usage.rst b/docs/usage.rst index 3f94f90..f7821d7 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -63,7 +63,7 @@ Creating a new Check client = Client(api_key="myapikey") - check = client.create_check(CheckCreate(name="New Check", tags="tag1 tag2") + check = client.create_check(CheckCreate(name="New Check", tags="tag1 tag2")) print(check) Getting a Check @@ -96,6 +96,7 @@ If you want to use the client in an async program, use AsyncClient instead of Cl .. code-block:: python + import asyncio from healthchecks_io import AsyncClient, CheckCreate async def main(): @@ -117,28 +118,30 @@ That's what CheckTrap is for. .. code-block:: python + import asyncio from healthchecks_io import Client, AsyncClient, CheckCreate, CheckTrap - client = Client(api_key="myapikey") + def run_my_thing_to_monitor(): + pass - # create a new check, or use an existing one already with just its uuid. - check = await client.create_check(CreateCheck(name="New Check", tags="tag1 tag2") + async def main(check): + client = AsyncClient(ping_key="ping_key") - with CheckTrap(client, check.uuid): - # when entering the context manager, sends a start ping to your check - run_my_thing_to_monitor() + # works with async too, and the ping api and slugs + async with CheckTrap(client, check.slug) as ct: + # when entering the context manager, sends a start ping to your check + # Add custom logs to what gets sent to healthchecks. Reminder, only the first 10k bytes get saved + ct.add_log("My custom log message") + run_my_thing_to_monitor() - # If your method exits without an exception, sends a success ping - # If there's an exception, a failure ping will be sent with the exception and traceback + if __name__ == "__main__": + client = Client(api_key="myapikey") - client = AsyncClient(ping_key="ping_key") + # create a new check, or use an existing one already with just its uuid. + check = await client.create_check(CreateCheck(name="New Check", tags="tag1 tag2") - # works with async too, and the ping api and slugs - async with CheckTrap(client, check.slug) as ct: - # when entering the context manager, sends a start ping to your check - # Add custom logs to what gets sent to healthchecks. Reminder, only the first 10k bytes get saved - ct.add_log("My custom log message") - run_my_thing_to_monitor() + with CheckTrap(client, check.uuid): + # when entering the context manager, sends a start ping to your check + run_my_thing_to_monitor() - # If your method exits without an exception, sends a success ping - # If there's an exception, a failure ping will be sent with the exception and traceback + asyncio.run(main())