Skip to main content

A simple backend agnostic heartbeating convention

Project description

beatit

A simple backend agnostic heartbeating convention.

    >>> class Printer:
    ...     @staticmethod
    ...     def publish(subject, *, payload):
    ...         print(f"{payload} -> {subject}")
    >>> heart = _Sync(process="my.process.identifier", publisher=Printer)
    >>> heart.start(warmup=60)
    b'start/60' -> b'heartbeat.my.process.identifier'
    >>> heart.beat(period=5)
    b'beat/5' -> b'heartbeat.my.process.identifier'
    >>> heart.beat(period=5)
    >>> heart.degraded(period=5)
    b'degraded/5' -> b'heartbeat.my.process.identifier'
    >>> heart.degraded(period=5)
    >>> heart.stop()
    b'stop' -> b'heartbeat.my.process.identifier'

All you need is a publisher with a publish method accepting a positional subject parameter and a named payload.

Instantiate a Heart instance with a process name and a publisher. beats will be published on the subject heartbeat.<process>.

What are the beats?

start with a warmup period (after which a beat or a degraded is expected)

beat with a period (when to expect the next beat).

degraded with a period (when to expect a beat or a degraded next).

stop when the process stops gracefully.

sync or not .,,

If you favour async (what is wrong with you?) Heart recognizes an async publisher automagically and all you have to do is await all the things.

    >>> class AsyncPrinter:
    ...     @staticmethod
    ...     async def publish(subject, *, payload):
    ...         print(f"{payload} -> {subject}")
    >>> heart = _Async(process="my.process.identifier", publisher=AsyncPrinter)
    >>> asyncio.run(heart.start(warmup=60))
    b'start/60' -> b'heartbeat.my.process.identifier'
    >>> asyncio.run(heart.beat(period=5))
    b'beat/5' -> b'heartbeat.my.process.identifier'
    >>> asyncio.run(heart.beat(period=5))
    >>> asyncio.run(heart.degraded(period=5))
    b'degraded/5' -> b'heartbeat.my.process.identifier'
    >>> asyncio.run(heart.degraded(period=5))
    >>> asyncio.run(heart.stop())
    b'stop' -> b'heartbeat.my.process.identifier'

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

beatit-2022.3.0.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

beatit-2022.3.0-py2.py3-none-any.whl (3.3 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file beatit-2022.3.0.tar.gz.

File metadata

  • Download URL: beatit-2022.3.0.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.27.1

File hashes

Hashes for beatit-2022.3.0.tar.gz
Algorithm Hash digest
SHA256 3b6aa1dce331fdd7c48b7c218800d6d384c18932af26b7ea6422823153a17ded
MD5 e60000dc6a3cf7fdadb3cc7ad6e14d86
BLAKE2b-256 266a54fd106b4a6557375833a63ba9b47270e2aed581f2f4fa21c270304c9362

See more details on using hashes here.

File details

Details for the file beatit-2022.3.0-py2.py3-none-any.whl.

File metadata

  • Download URL: beatit-2022.3.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 3.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.27.1

File hashes

Hashes for beatit-2022.3.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 c816081f44bb558129309f84a88ae6982f3451a4ac7253ffc87b3c6c2fe22dd3
MD5 e29e5b334d2ee6b498693ce5fb5765b9
BLAKE2b-256 69d17bd9b557b9e67012c3caeb32813447815f7a4071c53a7ea87bcf0b231ec9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page