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

feat: initial work to separate task processor from main repository #1

Merged
merged 20 commits into from
Feb 12, 2024

Conversation

matthewelwell
Copy link
Contributor

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)

@matthewelwell matthewelwell force-pushed the init branch 2 times, most recently from 6f97238 to 5b62dc4 Compare January 19, 2024 13:33
Copy link

@zachaysan zachaysan left a 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.

Comment on lines +7 to +14
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?"
)

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.

Copy link
Contributor Author

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()

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?

Copy link
Contributor Author

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

Flagsmith/flagsmith#3403

pyproject.toml Outdated Show resolved Hide resolved
readme.md Outdated Show resolved Hide resolved
readme.md Outdated Show resolved Hide resolved
task_processor/admin.py Outdated Show resolved Hide resolved
Comment on lines +163 to +165
if not os.environ.get("RUN_BY_PROCESSOR"):
# Do not register recurring tasks if not invoked by task processor
return lambda f: f

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?

Copy link
Contributor Author

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?

Copy link
Member

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/management/commands/runprocessor.py Outdated Show resolved Hide resolved


class TaskManager(Manager):
def get_tasks_to_process(self, num_tasks):

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/migrations/helpers/__init__.py Outdated Show resolved Hide resolved
@@ -2,10 +2,10 @@


class TaskManager(Manager):
def get_tasks_to_process(self, num_tasks):
def get_tasks_to_process(self, num_tasks: int):

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

Choose a reason for hiding this comment

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

I like this change 👍🏼

Copy link

@zachaysan zachaysan left a 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!

Copy link

@zachaysan zachaysan left a comment

Choose a reason for hiding this comment

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

PR looks good!

@matthewelwell matthewelwell merged commit f9c181a into main Feb 12, 2024
2 checks passed

services:
postgres:
image: postgres:11.12-alpine
Copy link
Member

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']
Copy link
Member

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?

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