Context
I want to add heartbeat monitoring mechanism to my worker-consumer-processes. Heartbeat means that either some useful work was done, or processes attempted to fetch data but received nothing from broker. It will be implemented with prometheus counter metric. If heartbeat is registered that it will mean that worker is alive and well, otherwise if there are no heartbeats for some time, then we should send an alert.
Problem
With other libs like aiokafka
implementation is quite easy:
messages = consumer.fetch()
if messages:
try:
handle(messages)
except: ...
else:
heartbeat() # worker handled messages properly
else:
heartbeat() # worker didn't fetch anything, but it's alive, so here is heartbeat
But faust
allows to process only non-empty fetched list of messages, so I cannot add heartbeat to "fetched nothing" phase, and it will mean that when there is nothing to process then alerting will be triggered.
There are some kind of sensors, but they don't seem to have needed callbacks.