Task queue based on Django models.
OTHER License
ModelQueue
_ is an Apache2 licensed task queue based on Django models.
For example, in appname/models.py::
import modelqueue
from django.db import models
class Task(models.Model):
data = models.TextField()
status = modelqueue.StatusField(
# ^-- Just a models.BigIntegerField
db_index=True,
# ^-- Index for faster queries.
default=modelqueue.Status.waiting,
# ^-- Waiting state is ready to run.
)
And in appname/management/commands/process_tasks.py::
import modelqueue, time
from django.core.management.base import BaseCommand
from .models import Task
class Command(BaseCommand):
def handle(self, *args, **options):
while True:
task = modelqueue.run(
Task.objects.all(),
# ^-- Queryset of models to process.
'status',
# ^-- Field name for model queue.
self.process,
# ^-- Callable to process model.
)
if task is None:
time.sleep(1)
# ^-- Bring your own parallelism/concurrency.
def process(self, task):
pass # Process task models.
And in appname/admin.py::
class TaskAdmin(admin.ModelAdmin):
actions = [*modelqueue.admin_actions('status')]
# ^-- Change task status in admin.
list_filter = [
modelqueue.admin_list_filter('status'),
# ^-- Filter tasks in admin by queue state.
]
def get_changeform_initial_data(self, request):
# v-- Automatically fill in status field when adding a new task.
return {'status': int(modelqueue.Status.waiting())}
ModelQueue
_ is a hazardous project. It takes a bad idea and makes it easy and
effective. You may come to regret using your database as a task queue but it
won't be today!
"I didn't design relational database systems for this." ~ Edgar Codd
_
"Well, at least you're using transactions." ~ Jim Gray
_
"You have successfully ignored most of what's important in queueing theory." ~
Agner Erlang
_
.. _Edgar Codd
: https://en.wikipedia.org/wiki/Edgar_F._Codd
.. _Jim Gray
: https://en.wikipedia.org/wiki/Jim_Gray_(computer_scientist)
.. _Agner Erlang
: https://en.wikipedia.org/wiki/Agner_Krarup_Erlang
Does your company or website use ModelQueue
? Send us a message <[email protected]>
and let us know.
.. image:: https://github.com/grantjenks/django-modelqueue/workflows/integration/badge.svg :target: https://github.com/grantjenks/django-modelqueue/actions?query=workflow%3Aintegration
.. image:: https://github.com/grantjenks/django-modelqueue/workflows/release/badge.svg :target: https://github.com/grantjenks/django-modelqueue/actions?query=workflow%3Arelease
Installing ModelQueue
_ is simple with pip <https://pypi.org/project/pip/>
_::
$ python -m pip install modelqueue
You can access documentation in the interpreter with Python's built-in help function::
>>> import modelqueue
>>> help(modelqueue)
For those wanting more details, this part of the documentation describes introduction, benchmarks, development, and API.
ModelQueue API Reference
_.. _ModelQueue API Reference
: http://www.grantjenks.com/docs/modelqueue/api.html
ModelQueue Documentation
_ModelQueue at PyPI
_ModelQueue at GitHub
_ModelQueue Issue Tracker
_.. _ModelQueue Documentation
: http://www.grantjenks.com/docs/modelqueue/
.. _ModelQueue at PyPI
: https://pypi.python.org/pypi/modelqueue/
.. _ModelQueue at GitHub
: https://github.com/grantjenks/django-modelqueue/
.. _ModelQueue Issue Tracker
: https://github.com/grantjenks/django-modelqueue/issues/
Copyright 2022 Grant Jenks
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
.. _ModelQueue
: http://www.grantjenks.com/docs/modelqueue/