Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add events for Flower #81

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open

Add events for Flower #81

wants to merge 16 commits into from

Conversation

gersh
Copy link

@gersh gersh commented Aug 2, 2023

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

@gersh gersh requested a review from clokep as a code owner August 2, 2023 18:11
@clokep
Copy link
Owner

clokep commented Aug 2, 2023

Any chance that tests could be added for this?

@gersh
Copy link
Author

gersh commented Aug 2, 2023

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.

@clokep
Copy link
Owner

clokep commented Aug 3, 2023

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
Copy link
Owner

clokep commented Aug 3, 2023

See also #70.

@clokep
Copy link
Owner

clokep commented Aug 5, 2024

@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:

- name: "Install dependencies"
run: python -m pip install -r requirements/pkgutils.txt
- name: "Run pyupgrade"
run: pyupgrade --py37-plus **/*.py
- name: "Run flake8"
run: flake8
- name: "Run isort"
run: isort --check .
- name: "Run black"
run: black --check .
- name: "Run mypy"
run: mypy

@gersh
Copy link
Author

gersh commented Aug 5, 2024

@clokep I think I fixed the lint issues.

@gersh
Copy link
Author

gersh commented Aug 6, 2024

@clokep I fixed all the lint issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants