mirror of
https://github.com/andrewthetechie/py-healthchecks.io.git
synced 2026-05-01 11:17:06 +02:00
more example fixes
This commit is contained in:
@@ -63,7 +63,7 @@ Creating a new Check
|
|||||||
|
|
||||||
client = Client(api_key="myapikey")
|
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)
|
print(check)
|
||||||
|
|
||||||
Getting a 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
|
.. code-block:: python
|
||||||
|
|
||||||
|
import asyncio
|
||||||
from healthchecks_io import AsyncClient, CheckCreate
|
from healthchecks_io import AsyncClient, CheckCreate
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
@@ -117,28 +118,30 @@ That's what CheckTrap is for.
|
|||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
|
import asyncio
|
||||||
from healthchecks_io import Client, AsyncClient, CheckCreate, CheckTrap
|
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.
|
async def main(check):
|
||||||
check = await client.create_check(CreateCheck(name="New Check", tags="tag1 tag2")
|
client = AsyncClient(ping_key="ping_key")
|
||||||
|
|
||||||
with CheckTrap(client, check.uuid):
|
# works with async too, and the ping api and slugs
|
||||||
# when entering the context manager, sends a start ping to your check
|
async with CheckTrap(client, check.slug) as ct:
|
||||||
run_my_thing_to_monitor()
|
# 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 __name__ == "__main__":
|
||||||
# If there's an exception, a failure ping will be sent with the exception and traceback
|
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
|
with CheckTrap(client, check.uuid):
|
||||||
async with CheckTrap(client, check.slug) as ct:
|
# when entering the context manager, sends a start ping to your check
|
||||||
# when entering the context manager, sends a start ping to your check
|
run_my_thing_to_monitor()
|
||||||
# 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
|
asyncio.run(main())
|
||||||
# If there's an exception, a failure ping will be sent with the exception and traceback
|
|
||||||
|
|||||||
Reference in New Issue
Block a user