Skip to main content

Django application provides simple task model, admin, server services and client service.

Project description

django-simpletask

Django application provides simple task model, admin, server services and client service.

Install

pip install django-simpletask

Usage

pro/settings

INSTALLED_APPS = [
    'django_db_lock',
    'django_simpletask',
]

DJANGO_SIMPLETASK_ACLKEY = "TsE9Jd3TrUtTA9wjGCLXoDqh891srpyo"

Note:

  • Mostly you need a lock service, so we add django_db_lock in INSTALLED_APPS.
  • Set DJANGO_SIMPLETASK_ACLKEY to your own aclkey. It will be used in task executor.

app/models.py

from django.db import models
from django_simpletask.models import SimpleTask

class Task1(SimpleTask):
    title = models.CharField(max_length=64)

    class Meta:
        permissions = [] + SimpleTask.Meta.permissions

    def do_task_main(self):
        return "done!"

class Task2(SimpleTask):
    title = models.CharField(max_length=64)

    class Meta:
        permissions = [] + SimpleTask.Meta.permissions

    def do_task_main(self):
        return "done!"

Note:

  • Write your own task model based on SimpleTask.
  • Add task reset permission.
  • Implement you own do_task_main.

app/admin.py

from django.contrib import admin
from django_simpletask.admin import SimpleTaskAdmin
from .models import Task1
from .models import Task2


class TaskAdmin(SimpleTaskAdmin, admin.ModelAdmin):
    list_display = ["title"] + SimpleTaskAdmin.list_display


admin.site.register(Task1, TaskAdmin)
admin.site.register(Task2, TaskAdmin)

Note:

  • Mostly we don't want to change anything inside task, so we set task fields readonly.

task_executor.py

from daemon_application.app import DaemonApplication
from django_simpletask.services import SimpleTaskService

class TaskExcutor(DaemonApplication):
    def main(self):
        service = SimpleTaskService("http://127.0.0.1:8000/example/task/services/", aclkey="TsE9Jd3TrUtTA9wjGCLXoDqh891srpyo")
        service.start()
        service.join()

app = TaskExcutor().get_controller()

if __name__ == "__main__":
    app()

Note:

  • Add task_executor.py script.
  • Set the server to your own url.
  • Set the aclkey match the DJANGO_SIMPLETASK_ACLKEY setting.

Release

v0.1.0

  • First release.
  • Take from django-fastadmin. django-fastadmin should forcus on admin extensions, but NOT abstract models.

v0.1.1

  • Add SimpleTask.do_tasks.

v0.1.2

  • Add SimpleTask.serve and SimpleTask.serve_forever.

v0.1.3

  • Add idle_sleep_time parameter for SimpleTask.serve_forever.

v0.1.6

  • Add reset action.
  • Add SimpleTask.force_finish.
  • Add multi-threads serve.

v0.2.2

  • Long running service don't use database.
  • Add aclkey check for simpletask apis.

v0.2.8

  • Add SimpleTaskServiceProxy and required views.
  • Add get_ready_tasks_queryset to SimpleTaskViews.

v0.2.9

  • Add channel params.

v0.3.5

  • Bad response handler.
  • Services changed a a lot.

v0.3.6

  • Doc update.

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

django-simpletask-0.3.6.tar.gz (14.1 kB view details)

Uploaded Source

Built Distribution

django_simpletask-0.3.6-py3-none-any.whl (16.0 kB view details)

Uploaded Python 3

File details

Details for the file django-simpletask-0.3.6.tar.gz.

File metadata

  • Download URL: django-simpletask-0.3.6.tar.gz
  • Upload date:
  • Size: 14.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for django-simpletask-0.3.6.tar.gz
Algorithm Hash digest
SHA256 c31027e12fa53ec1e4147d97171e9aebc09946895f996604705b604a677350c8
MD5 4fdb3165eaf7e1b7c18dfe2222cef7a0
BLAKE2b-256 06c49d264154c5651a096bec42d94594106f6bda6520d08e1ffcce01c9712d86

See more details on using hashes here.

File details

Details for the file django_simpletask-0.3.6-py3-none-any.whl.

File metadata

File hashes

Hashes for django_simpletask-0.3.6-py3-none-any.whl
Algorithm Hash digest
SHA256 44604e540a916135bf81ad0e16f23f50f38de3e8921ec7af6daf546c10aaaa9c
MD5 8fd35f85cc49067e394e581d24f44155
BLAKE2b-256 7cadd2197b36dcafea9bea8a3d95d4a7242d9e1b7c84bb3460fb7e35760b6180

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