From 11819ccae65d5c7ee58979cf742a6896208d6b0b Mon Sep 17 00:00:00 2001 From: Andrew Date: Sat, 22 Jan 2022 17:29:05 -0600 Subject: [PATCH 1/6] fix async example --- docs/usage.rst | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/docs/usage.rst b/docs/usage.rst index 964a6f6..323e2fd 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -13,7 +13,7 @@ Either the Client or AsyncClient can be used as a ContextManager (or Async Conte from healthchecks_io import AsyncClient, CheckCreate async with AsyncClient(api_key="myapikey") as client: - check = await client.create_check(CreateCheck(name="New Check", tags="tag1 tag2") + check = await client.create_check(CheckCreate(name="New Check", tags="tag1 tag2") print(check) This is probably the easiest way to use the Clients for one-off scripts. If you do not need to keep a client open for multiple requests, just use @@ -63,7 +63,7 @@ Creating a new Check client = Client(api_key="myapikey") - check = client.create_check(CreateCheck(name="New Check", tags="tag1 tag2") + check = client.create_check(CheckCreate(name="New Check", tags="tag1 tag2") print(check) Getting a Check @@ -99,11 +99,14 @@ If you want to use the client in an async program, use AsyncClient instead of Cl .. code-block:: python from healthchecks_io import AsyncClient, CheckCreate + + async def main(): + client = AsyncClient(api_key="myapikey") - client = AsyncClient(api_key="myapikey") - - check = await client.create_check(CreateCheck(name="New Check", tags="tag1 tag2") - print(check) + check = await client.create_check(CheckCreate(name="New Check", tags="tag1 tag2") + print(check) + if __name__ == "__main__": + asyncio.run(main()) CheckTrap From 40958b22816122feaeeb911f2ddda8558845b7af Mon Sep 17 00:00:00 2001 From: Andrew Date: Sat, 22 Jan 2022 17:32:16 -0600 Subject: [PATCH 2/6] Update usage.rst --- docs/usage.rst | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/docs/usage.rst b/docs/usage.rst index 323e2fd..f13db99 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -10,10 +10,10 @@ Either the Client or AsyncClient can be used as a ContextManager (or Async Conte .. code-block:: python - from healthchecks_io import AsyncClient, CheckCreate + from healthchecks_io import Client, CheckCreate - async with AsyncClient(api_key="myapikey") as client: - check = await client.create_check(CheckCreate(name="New Check", tags="tag1 tag2") + with Client(api_key="myapikey") as client: + check = client.create_check(CheckCreate(name="New Check", tags="tag1 tag2") print(check) This is probably the easiest way to use the Clients for one-off scripts. If you do not need to keep a client open for multiple requests, just use @@ -94,8 +94,6 @@ Async If you want to use the client in an async program, use AsyncClient instead of Client - - .. code-block:: python from healthchecks_io import AsyncClient, CheckCreate @@ -105,6 +103,7 @@ If you want to use the client in an async program, use AsyncClient instead of Cl check = await client.create_check(CheckCreate(name="New Check", tags="tag1 tag2") print(check) + if __name__ == "__main__": asyncio.run(main()) From 5f8cb5218350a12bef5e7189f407c1ed9db302cb Mon Sep 17 00:00:00 2001 From: Andrew Date: Sat, 22 Jan 2022 17:34:14 -0600 Subject: [PATCH 3/6] fix missing parens --- docs/usage.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/usage.rst b/docs/usage.rst index f13db99..0314bd8 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -13,7 +13,7 @@ Either the Client or AsyncClient can be used as a ContextManager (or Async Conte from healthchecks_io import Client, CheckCreate with Client(api_key="myapikey") as client: - check = client.create_check(CheckCreate(name="New Check", tags="tag1 tag2") + check = client.create_check(CheckCreate(name="New Check", tags="tag1 tag2")) print(check) This is probably the easiest way to use the Clients for one-off scripts. If you do not need to keep a client open for multiple requests, just use @@ -101,7 +101,7 @@ If you want to use the client in an async program, use AsyncClient instead of Cl async def main(): client = AsyncClient(api_key="myapikey") - check = await client.create_check(CheckCreate(name="New Check", tags="tag1 tag2") + check = await client.create_check(CheckCreate(name="New Check", tags="tag1 tag2")) print(check) if __name__ == "__main__": From d293d84fb81f3b316198927b49ed5c636aa6caa1 Mon Sep 17 00:00:00 2001 From: Andrew Herrington Date: Sat, 22 Jan 2022 17:47:19 -0600 Subject: [PATCH 4/6] pass pre-commit --- docs/usage.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/usage.rst b/docs/usage.rst index 0314bd8..3f94f90 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -97,13 +97,13 @@ If you want to use the client in an async program, use AsyncClient instead of Cl .. code-block:: python from healthchecks_io import AsyncClient, CheckCreate - + async def main(): client = AsyncClient(api_key="myapikey") check = await client.create_check(CheckCreate(name="New Check", tags="tag1 tag2")) print(check) - + if __name__ == "__main__": asyncio.run(main()) From 432fbebb2aff4399edb734e2a2d8ca962b489890 Mon Sep 17 00:00:00 2001 From: Andrew Herrington Date: Sat, 22 Jan 2022 17:56:05 -0600 Subject: [PATCH 5/6] more example fixes --- docs/usage.rst | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) 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()) From a085cb2f4d25e2ba30497985aa6a9805b0363c8f Mon Sep 17 00:00:00 2001 From: Andrew Herrington Date: Sat, 22 Jan 2022 18:07:33 -0600 Subject: [PATCH 6/6] one last tweak --- docs/usage.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/usage.rst b/docs/usage.rst index f7821d7..7305b64 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -128,7 +128,7 @@ That's what CheckTrap is for. client = AsyncClient(ping_key="ping_key") # works with async too, and the ping api and slugs - async with CheckTrap(client, check.slug) as ct: + async with CheckTrap(client, slug=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")