Skip to content
New issue

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

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

Already on GitHub? # to your account

Much better Django integration #906

Merged
merged 11 commits into from
Jan 24, 2024
Merged

Much better Django integration #906

merged 11 commits into from
Jan 24, 2024

Conversation

ewjoachim
Copy link
Member

@ewjoachim ewjoachim commented Jan 21, 2024

Closes #363

Successful PR Checklist:

  • Tests
    • (not applicable?)
  • Documentation
    • (not applicable?)

Tasks from #363

  • pip install procrastinate[django]

    • Already good
  • Add "procrastinate.contrib.django" to INSTALLED_APPS

    • Already good
  • Tweak one or two PROCRASTINATE_* variables inside Django's settings.py file

    • Done
  • Create tasks inside myapp/tasks.py, decorating them with procrastinate.task

    • I've chosen to use from procrastinate.contrib.django import app, @app.task
  • Run the worker with python manage.py procrastinate-worker (set DJANGO_SETTINGS_MODULE env var when running the worker)

    • I've chosen to use python manage.py procrastinate worker instead. Note that manage.py already
      sets DJANGO_SETTINGS_MODULE.
  • Monitor tasks inside Django Admin (running, finished, failed, waiting etc.)

    • For now it's the bare minimum. We can add proper filters etc in a subsequent PR.
  • Fix existing tests

  • Write new tests (especially, Django tests, and "Django ORM in tasks" tests including async ORM)

Breaking change announcement draft

This release refactors the Django integration completely. Head to the Django section in the doc to discover how it works.
Here's a summary of the changes:

  • You don't need to define an app anymore. As long as procrastinate is in your INSTALLED_APPS, you can use procrastinate.contrib.django.app. The app will be opened for you at the start of the process (during Django's setup) and will be properly closed when the process stops.
  • Tasks defined under the tasks submodule of any app in INSTALLED_APPS are loaded by default. This is configurable.
  • Some settings can be defined as PROCRASTINATE_* in your Django settings. They include specifying where your tasks are (among other things)
  • You can run the CLI with ./manage.py procrastinate (if you use that, you won't have to configure an App either)
  • Procrastinate now exposes 2 models and the corresponding ModelAdmins in your Django Admin. Those models are read-only. The Admin panels are very very basic for now.
  • Procrastinate is tested with Django tasks that call the classic django ORM and the new async ORM methods.

PR label(s):

@ewjoachim ewjoachim requested a review from a team as a code owner January 21, 2024 02:04
@ewjoachim ewjoachim marked this pull request as draft January 21, 2024 02:04
@github-actions github-actions bot added PR type: breaking 💥 Contains breaking changes PR type: feature ⭐️ Contains new features labels Jan 21, 2024
@ewjoachim
Copy link
Member Author

@turicas you will probably be interested by this PR. If you want more info, feel free to ask here or on the shiny new discord server (link at the top of the project README)

I'll need to fix the test, but otherwise, it's starting to look great.

@ewjoachim ewjoachim force-pushed the django branch 2 times, most recently from 1fd637e to bef22ca Compare January 23, 2024 23:37
@ewjoachim ewjoachim marked this pull request as ready for review January 23, 2024 23:38
Copy link

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  procrastinate
  cli.py
  connector.py
  psycopg_connector.py
  sync_psycopg_connector.py
  utils.py
  procrastinate/contrib/aiopg
  aiopg_connector.py
  procrastinate/contrib/django
  __init__.py
  apps.py 26
  django_connector.py 19-20
  exceptions.py
  models.py
  router.py 12-13
  utils.py
  procrastinate/contrib/django/management/commands
  procrastinate.py 17-18, 34-36, 41-48
Project Total  

This report was generated by python-coverage-comment-action

@ewjoachim ewjoachim merged commit ebf4f30 into main Jan 24, 2024
11 checks passed
@ewjoachim ewjoachim deleted the django branch January 24, 2024 23:50
This was referenced Jan 24, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
PR type: breaking 💥 Contains breaking changes PR type: feature ⭐️ Contains new features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve the django experience
1 participant