-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat: initial work to separate task processor from main repository #1
Conversation
6f97238
to
5b62dc4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't review the test code since I was already taking a while through the rest of it.
Most of these comments are more like questions or small suggestions, but I definitely think we should get the "make the tests pass" user experience better.
try: | ||
from django.core.management import execute_from_command_line | ||
except ImportError: | ||
raise ImportError( | ||
"Couldn't import Django. Are you sure it's installed and " | ||
"available on your PYTHONPATH environment variable? Did you " | ||
"forget to activate a virtual environment?" | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering why this is necessary here but not in the main flagsmith repo manage.py.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good question. I think the reason stems from the fact that I actually pulled it from flagsmith-ldap instead. The reason it's different there (I think) is that flagsmith/flagsmith repo was created with django 2.x (because old) whereas flagsmith-ldap was created with django 3.x. I guess the actionable change here would be to update manage.py in the flagsmith/flagsmith repository rather than change anything here.
A quick test shows my assumption is correct:
❯ python -m django startproject testingmanagepy
❯ cd testingmanagepy
❯ cat manage.py
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys
def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'testingmanagepy.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
if __name__ == '__main__':
main()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good. Maybe make a ticket so we don't forget to update the other one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just made the PR instead :)
if not os.environ.get("RUN_BY_PROCESSOR"): | ||
# Do not register recurring tasks if not invoked by task processor | ||
return lambda f: f |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should RUN_BY_PROCESSOR
be in settings.py
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a feeling there's a reason that this is done (perhaps because settings are loaded at the time we need the env var) and we copied it from somewhere in the django project itself I believe. @gagantrivedi may remember further details?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd argue that is not really a setting(in the global scope of things)
The use case, this:
# The `register_recurring_task` decorator is executed in the global scope,
# meaning it will run whenever the code is executed, including when running
# `manage.py` commands such as `migrate` or `showmigrations`. However, this
# decorator saves the task to the database, which is not desired unless it is
# being run by processor, and to indicate the we set this `RUN_BY_PROCESSOR`
# environment variable.
```
task_processor/managers.py
Outdated
|
||
|
||
class TaskManager(Manager): | ||
def get_tasks_to_process(self, num_tasks): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing typing here and below
task_processor/managers.py
Outdated
@@ -2,10 +2,10 @@ | |||
|
|||
|
|||
class TaskManager(Manager): | |||
def get_tasks_to_process(self, num_tasks): | |||
def get_tasks_to_process(self, num_tasks: int): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: missing return type here and below
|
||
from django.db import migrations | ||
from task_processor.migrations.helpers.postgres_helpers import PostgresOnlyRunSQL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this change 👍🏼
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I reviewed the committed changes, not the whole thing again. Lots of nice fixes!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR looks good!
|
||
services: | ||
postgres: | ||
image: postgres:11.12-alpine |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to bump Postgres version
strategy: | ||
max-parallel: 4 | ||
matrix: | ||
python-version: ['3.10', '3.11'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add 3.12
as well?
In order to use the task processor in other private modules, we need to separate out the task processor module into it's own repository.
This will be added as a poetry dependency in the main repository (using git tags)