Package: django-simpletask2
django-simpletask2A simple asynchronous task manager based on the Django framework. All business logic written in a custom task data model. Tasks are triggered by a Redis queue.Installpip install django-simpletask2Usagepro/settings.pyINSTALLED_APPS = [
    ...
    'django_simpletask2',
    ...
]

# requires redis cache backend, see django-redis for detail
CACHES = {
    "default": {
        "BACKEND": "django_redis.cache.RedisCache",
        "LOCATION": "redis://:xxx@xxx:6379/0?decode_responses=True",
    }
}

DJANGO_SIMPLETASK2_TASK_PULL_TIMEOUT = 5 # optional, default to 5
DJANGO_SIMPLETASK2_REDIS_NAME = "default" # optional, default to "default"
DJANGO_SIMPLETASK2_ACLKEY = "Bqud27SzhUymXDuBfvYNHJWQm0i4FdUB" # optional, default to settings.SECRET_KEYpro/urls.pyfrom django.urls import path
from django.urls import include

urlpatterns = [
    ...
    path('django-simpletask2/', include("django_simpletask2.urls")),
    ....
]app/models.pyimport base64
from django.db import models
from django_simpletask2.models import SimpleTask


class HelloTask(SimpleTask):
    name = models.CharField(max_length=64)

    def do_task_main(self, payload):
        return "Hello, {}. Nice to meet you!".format(self.name)

class WorldTask(SimpleTask):
    url = models.CharField(max_length=128)
    content = models.TextField(null=True, blank=True)

    is_multi_steps = True
    final_step = 2

    def do_task_main_step1(self, payload=None):
        return {
            "proxy": {
                "method": "GET",
                "url": self.url,
            }
        }
    
    def do_task_main_step2(self, payload=None):
        payload = payload or {}
        base64content = payload.get("proxied_content", None)
        if base64content:
            try:
                content = base64.decodebytes(base64content.encode()).decode("utf-8")
                success = True
            except UnicodeDecodeError:
                try:
                    content = base64.decodebytes(base64content.encode()).decode("gb18030")
                    success = True
                except UnicodeDecodeError:
                    content = "failed to decode proxied_content: {0}".format(base64content)
                    success = False
        else:
            content = payload.get("proxied_error", None)
            success = False

        self.content = content
        self.save()

        if success:
            return True
        else:
            raise RuntimeError("WorldTask.do_task_main_step2 failed....")etc/django-simpletask2-server-config.ymlredis: "redis://:xxx@xxx:6379/0?decode_responses=True"
channels: default
server: https://localhost:80000/django-simpletask2/
aclkey: xxxx
task-pull-engine: redis
threads: 1
idle-sleep: 5
error-sleep: 5
auto-reset-task-interval: 60
do-auto-reset-task: trueStart django-simpletask2-server to trigger tasksdjango-simpletask2-server --config etc/django-simpletask2-server-config.yml startError CodesCodeMessage2910000system error.2910001please send request parameters in PAYLOAD format.2910002aclkeyfield is required.2910003aclkey is wrong and access denied.2910004got an already deleted task {task_info}, you may ignore this and continue.2910005bad formatted task_info: {task_info}.2910006Simple task model {task_class_name} not exists.2910007task handler is not implemented, task={app_label}.{model_name}, handler={}.2910008task status is not READY but {status}, you can not start it.2910009calling {handler_name} failed with error message: {error}.2910010save task done status failed with error message: {error}.2910011task_infofield is required for a multi-steps task. payload={payload}.2910012got NO task in channels: {channels}.2910013task {task_info} locked by another worker.2910014task {app_label}.{model_name}:{task_id} failed to save status with error message: {error}.2910015task_infofield is required.2910016get task instance {task_info} failed with error: {error}.Releasesv0.0.1First release.v0.0.4Fixed the problem that the task duplicately executed for the task queue is too long.v0.0.5Fix do_task problem in actions.Fix ugettext_lazy problem.Fix problems in django 4.x.v0.0.6Doc update.v0.0.7Fix error message formatting problem.v0.0.8Push to mq after instance-create-transaction committed.v0.1.9Add SimpleTaskQueue and SimpleTaskChannel management.