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

Close #9: Support multiple concurrent worker processes #20

Merged
merged 4 commits into from
Aug 29, 2022

Conversation

imranariffin
Copy link
Owner

@imranariffin imranariffin commented Aug 20, 2022

Features:

  • Accept --concurrency N option and spawn N workers
  • Wait for child workers ready before propagate msg
  • Ensure worker exit early with message when app path invalid
  • Make parallel requests when checking for ready workers

Dev features & tech debts:

  • Ensure run some tests asynchronously
  • Remove unnecessary GithubAction workflow
  • Add docstrings to some modules, classes and functions
  • Cleanup using pylint and black (Will add pylint to CI in the future)
  • Allow specify test pattern on ./test.sh

Notes:
Currently we see this warning when running the tests:

Task was destroyed but it is pending!
task: <Task pending name='Task-5' coro=<Connection.disconnect() done, defined at /home/in-gote/workspace/aiotaskq/.venv/lib/python3.10/site-packages/aioredis/connection.py:794> wait_for=<Future pending cb=[Task.task_wakeup()]>>

We should fix it in the future.

Also, currently because in some tests (e.g.
test_integration.test_sync_and_async_parity__simple_app) we're
starting the worker in a sub-process, coverage doesn't count
anything in worker.py. I tried following this guide, but I couldn't get it to work. Maybe I missed something.

We also need to fix this in the future. We should consider either:

  1. Start the worker using multiprocessing instead of subprocess
  2. Somehow follow the guide correctly

@codecov-commenter
Copy link

codecov-commenter commented Aug 20, 2022

Codecov Report

Merging #20 (660e52f) into main (84c18b7) will decrease coverage by 38.04%.
The diff coverage is 60.19%.

@@             Coverage Diff             @@
##             main      #20       +/-   ##
===========================================
- Coverage   97.90%   59.85%   -38.05%     
===========================================
  Files           6        9        +3     
  Lines         143      274      +131     
===========================================
+ Hits          140      164       +24     
- Misses          3      110      +107     
Impacted Files Coverage Δ
src/aiotaskq/__main__.py 0.00% <0.00%> (ø)
src/aiotaskq/constants.py 100.00% <ø> (ø)
src/aiotaskq/worker.py 0.00% <0.00%> (-100.00%) ⬇️
src/aiotaskq/main.py 96.87% <91.66%> (+0.10%) ⬆️
src/aiotaskq/tests/apps/simple_app.py 94.73% <94.73%> (ø)
src/aiotaskq/__init__.py 100.00% <100.00%> (ø)
src/aiotaskq/exceptions.py 100.00% <100.00%> (ø)
src/aiotaskq/tests/test_cli.py 100.00% <100.00%> (ø)
src/aiotaskq/tests/test_integration.py 100.00% <100.00%> (ø)
... and 1 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@imranariffin imranariffin force-pushed the 9/support-multiple-concurrent-processes branch 4 times, most recently from 69ebdc7 to ea32f3c Compare August 21, 2022 22:00
@imranariffin imranariffin marked this pull request as ready for review August 21, 2022 22:02
@imranariffin
Copy link
Owner Author

imranariffin commented Aug 21, 2022

@cglotr Please review when you have time. See issue #9 for the high level idea. Please ignore the missing test coverage for now, I'll try to fill it if possible, but if not I'll fix it in the future (See PR description for why).

Features:
* Accept --concurrency N option and spawn N workers
* Wait for child workers ready before propagate msg
* Ensure worker exit early with message when app path invalid
* Make parallel requests when checking for ready workers

Dev features & tech debts:
* Ensure run some tests asynchronously
* Remove unnecessary GithubAction workflow
* Add docstrings to some modules, classes and functions
* Cleanup using pylint and black (Will add pylint to CI in the future)
* Allow specify test pattern on ./test.sh

Notes:
Currently we see this warning when running the tests:
```
Task was destroyed but it is pending!
task: <Task pending name='Task-5' coro=<Connection.disconnect()\
 done, defined at /home/in-gote/workspace/aiotaskq/.venv/lib/\
python3.10/site-packages/aioredis/connection.py:794> wait_for=<\
Future pending cb=[Task.task_wakeup()]>>
```

We should fix it in the future.

Also, currently because in some tests (e.g.
`test_integration.test_sync_and_async_parity__simple_app`) we're
starting the worker in a sub-process, `coverage` doesn't count
anything in worker.py. I tried following this guide: https://
coverage.readthedocs.io/en/6.4.4/api_module.html#coverage.process
_startup, but I couldn't get it to work. Maybe I missed something.

We also need to fix this in the future. We should consider either:

1. Start the worker using `multiprocessing` instead of `subprocess`
2. Somehow follow the guide correctly
@imranariffin imranariffin force-pushed the 9/support-multiple-concurrent-processes branch from ea32f3c to 07e0de6 Compare August 21, 2022 22:07
src/aiotaskq/worker.py Outdated Show resolved Hide resolved
src/aiotaskq/worker.py Outdated Show resolved Hide resolved
src/aiotaskq/worker.py Show resolved Hide resolved
@imranariffin
Copy link
Owner Author

@cglotr I've applied the requested changes, and also added some more docstrings & delinting. Please review the last two commits when you have time.

src/aiotaskq/worker.py Outdated Show resolved Hide resolved
@cglotr cglotr self-assigned this Aug 29, 2022
Copy link
Collaborator

@cglotr cglotr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm but added a new comment

@imranariffin imranariffin merged commit 136ae39 into main Aug 29, 2022
@imranariffin imranariffin deleted the 9/support-multiple-concurrent-processes branch August 29, 2022 21:57
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.

3 participants