build-system icon indicating copy to clipboard operation
build-system copied to clipboard

Keep track of background tasks statuses

Open forbiddenpotato opened this issue 1 year ago • 0 comments

We explored the possibility to keep track of background tasks that are sent.

This would involve:

  • Creating a new table background_tasks in db that includes the build task (or release, or whatever task that is done through dramatiq), status and tiimestamp
  • Create a small middleware that updates the records in the background_tasks table

The most interesting background tasks to track are the build-related ones, but can also be applied to anything we do with dramatiq.

Here’s a small example of the middleware we can create

class MyMiddleware(Middleware):
    def after_process_message(self, _broker, _message, *, result=None, exception=None):
        print("after_process_message, result:", result)

    def before_process_message(self, _broker, _message):
        print("before_process_message")

    def after_enqueue(self, _broker, _message, _delay):
        print("after_enqueue")

    def before_enqueue(self, _broker, _message, _delay):
        print("before_enqueue")

    def before_ack(self, _broker, _message):
        print("before_ack")

rabbitmq_broker = RabbitmqBroker(
    url=f"amqp://<USER>:<PASSWORD>@<HOST>:<PORT>/<VHOST>",
    middleware=[MyMiddleware()]
)
dramatiq.set_broker(rabbitmq_broker)

forbiddenpotato avatar Apr 12 '24 09:04 forbiddenpotato