Skip to main content

Task queue based on Django models.

Project description

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!

Testimonials

“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

Does your company or website use ModelQueue? Send us a message and let us know.

Features

  • Pure-Python

  • Supports Django’s admin interface

  • Tasks can be retried, aborted, and canceled

  • Supports multiple attempts per task

  • Bring your own parallelism with threading, multiprocessing, or asyncio

  • Performance matters (add a single 64-bit field to models)

  • Fully documented

  • 100% test coverage

  • Years of stress testing in production

  • Developed on Python 3.10

  • Compatible with all Django versions

  • Tested on CPython 3.6, 3.7, 3.8, 3.9, 3.10

  • Tested on Linux, Mac OS X, and Windows

https://github.com/grantjenks/django-modelqueue/workflows/integration/badge.svg https://github.com/grantjenks/django-modelqueue/workflows/release/badge.svg

Quickstart

Installing ModelQueue is simple with pip:

$ python -m pip install modelqueue

You can access documentation in the interpreter with Python’s built-in help function:

>>> import modelqueue
>>> help(modelqueue)

User Guide

For those wanting more details, this part of the documentation describes introduction, benchmarks, development, and API.

Reference and Indices

ModelQueue License

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

modelqueue-2.2.0.tar.gz (8.5 kB view details)

Uploaded Source

Built Distribution

modelqueue-2.2.0-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file modelqueue-2.2.0.tar.gz.

File metadata

  • Download URL: modelqueue-2.2.0.tar.gz
  • Upload date:
  • Size: 8.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for modelqueue-2.2.0.tar.gz
Algorithm Hash digest
SHA256 3f6ee590022479e530afdf0e0f42b5518393d42f68081f6b7b428f0cffb6da70
MD5 f0e191fa824ed9d43683fda8695004bf
BLAKE2b-256 7b9eda1b65c376e88c2651844f3929e8ecb1b8eed732c007a165035a02772f2b

See more details on using hashes here.

File details

Details for the file modelqueue-2.2.0-py3-none-any.whl.

File metadata

  • Download URL: modelqueue-2.2.0-py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for modelqueue-2.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3fb50e0b97712c7f672d20e93b01a4dab5284334d390d9b57d91ef03b2d3c5e7
MD5 51b29745eacc0cb3db69dd22a331e2da
BLAKE2b-256 bb52046e771fe9e8c67072ab4cf2b375766e9d5add5386e6e914015543296014

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page