celery-batches icon indicating copy to clipboard operation
celery-batches copied to clipboard

Add events for Flower

Open gersh opened this issue 2 years ago • 8 comments

Add "task-*" events so we can monitor the queue with Flower.

gersh avatar Aug 02 '23 18:08 gersh

Any chance that tests could be added for this?

clokep avatar Aug 02 '23 19:08 clokep

Is there a good way to test if a signal has been sent with pytest? I tried:

    class TaskMonitor:
        def __init__(self):
            self.tasks_received = 0
            self.tasks_started = 0
            self.tasks_suceeded = 0

        def on_task_received(self, event):
            self.tasks_received += 1
        def on_task_started(self, event):
            self.tasks_started += 1
        def on_task_suceeded(self, event):
            self.tasks_suceeded += 1

    tm = TaskMonitor()

    recv = celery_app.events.Receiver(connection, handlers={
            'task-received': tm.on_task_received,
            'task-started': tm.on_task_started,
            'task-suceeded': tm.on_task_suceeded,
            '*': tm.on_other
            })

but I can't seem to get it to work. If you can help me figure out how to get it to listen for events in a pytest, I can implement it. I tested it in Flower, and it seems to work, but I'm not sure how to get the internals to work for a unit test.

gersh avatar Aug 02 '23 21:08 gersh

Some of the tests use the SignalCounter class to do this (it is a bit hacky, but I haven't managed to figure out a better way to do it).

clokep avatar Aug 03 '23 11:08 clokep

See also #70.

clokep avatar Aug 03 '23 11:08 clokep

@gersh Shout when you think this is ready for review again!

You should be able to run the lints locally manually by running the same commands as CI:

https://github.com/clokep/celery-batches/blob/59cc04f9c0220581fd84a1116cd390ddc6a799ec/.github/workflows/main.yml#L23-L39

clokep avatar Aug 05 '24 18:08 clokep

@clokep I think I fixed the lint issues.

gersh avatar Aug 05 '24 19:08 gersh

@clokep I fixed all the lint issues.

gersh avatar Aug 06 '24 20:08 gersh