Giter VIP home page Giter VIP logo

django-background-tasks-example's Introduction

django-background-tasks-example

This example shows how to set up and use django-background-tasks.

Usage

Install project dependencies

pip install -r requirements.txt

Prepare database

cd project
python manage.py migrate

Start the server.

python manage.py runserver

Register a task (on separate terminal)

curl -d message=hello http://localhost:8000/api/v1/tasks/

Process tasks

python manage.py process_tasks

django-background-tasks-example's People

Contributors

collinmutembei avatar dependabot[bot] avatar hnakamur avatar philippeowagner avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

django-background-tasks-example's Issues

Questions

First an observation. Due to using 2 processes, I think this excludes using sqlite databases, as they have exclusive locks. Is that correct?

Second, I was looking at models.py and didn't see any tables described. I was surprised. This means that when restarted, there is no state for tasks, they will need to be newly scheduled.

My intended use case is to allow the user to add tasks to import information, which will be very long running and good as a separate, non-blocking process, much like run-tasks is. I really would want that information to be persistent, as some of these tasks are more like continuous observations.

Now I wonder (also since the example doesn't run for me, see other issue) if there is any value at all in background tasks, maybe because I lack Django knowledge. Will I not be able to import models from the second app in another project, even multiple processes, and insert data and execute tasks with say cron/at or systemd timers instead.

I didn't go deep enough to see it in the code, but what method of IPC, if not the database, is runtasks using to talk to runserver, and how does it interact with wsgi. I am kind of thinking I just missed out on the model.

Crashes with latest Python3.6 and Django

This is what I have:

Django==2.0.4
django-background-tasks==1.1.13
django-compat==1.0.15

And doing runserver with python3.6 does this:

erforming system checks...

Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x7fa0694ed840>
Traceback (most recent call last):
  File "/opt/python363/lib/python3.6/site-packages/django/urls/conf.py", line 17, in include
    urlconf_module, app_name = arg
ValueError: too many values to unpack (expected 2)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/python363/lib/python3.6/site-packages/django/utils/autoreload.py", line 225, in wrapper
    fn(*args, **kwargs)
  File "/opt/python363/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 120, in inner_run
    self.check(display_num_errors=True)
  File "/opt/python363/lib/python3.6/site-packages/django/core/management/base.py", line 364, in check
    include_deployment_checks=include_deployment_checks,
  File "/opt/python363/lib/python3.6/site-packages/django/core/management/base.py", line 351, in _run_checks
    return checks.run_checks(**kwargs)
  File "/opt/python363/lib/python3.6/site-packages/django/core/checks/registry.py", line 73, in run_checks
    new_errors = check(app_configs=app_configs)
  File "/opt/python363/lib/python3.6/site-packages/django/core/checks/urls.py", line 40, in check_url_namespaces_unique
    all_namespaces = _load_all_namespaces(resolver)
  File "/opt/python363/lib/python3.6/site-packages/django/core/checks/urls.py", line 57, in _load_all_namespaces
    url_patterns = getattr(resolver, 'url_patterns', [])
  File "/opt/python363/lib/python3.6/site-packages/django/utils/functional.py", line 36, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/opt/python363/lib/python3.6/site-packages/django/urls/resolvers.py", line 536, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "/opt/python363/lib/python3.6/site-packages/django/utils/functional.py", line 36, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/opt/python363/lib/python3.6/site-packages/django/urls/resolvers.py", line 529, in urlconf_module
    return import_module(self.urlconf_name)
  File "/opt/python363/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/hayen/repos/django-background-tasks-example/project/project/urls.py", line 20, in <module>
    url(r'^admin/', include(admin.site.urls)),
  File "/opt/python363/lib/python3.6/site-packages/django/urls/conf.py", line 27, in include
    'provide the namespace argument to include() instead.' % len(arg)
django.core.exceptions.ImproperlyConfigured: Passing a 3-tuple to include() is not supported. Pass a 2-tuple containing the list of patterns and app_name, and provide the namespace argument to include() instead.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.