django-simpletask2
A 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.
Install
pip install django-simpletask2
Usage
pro/settings.py
INSTALLED_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_KEY
pro/urls.py
from django.urls import path
from django.urls import include
urlpatterns = [
...
path('django-simpletask2/', include("django_simpletask2.urls")),
....
]
app/models.py
import 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.yml
redis: "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: true
Start django-simpletask2-server to trigger tasks
django-simpletask2-server --config etc/django-simpletask2-server-config.yml start
Error Codes
| Code | Message |
|---|---|
| 2910000 | system error. |
| 2910001 | please send request parameters in PAYLOAD format. |
| 2910002 | aclkey field is required. |
| 2910003 | aclkey is wrong and access denied. |
| 2910004 | got an already deleted task {task_info}, you may ignore this and continue. |
| 2910005 | bad formatted task_info: {task_info}. |
| 2910006 | Simple task model {task_class_name} not exists. |
| 2910007 | task handler is not implemented, task={app_label}.{model_name}, handler={}. |
| 2910008 | task status is not READY but {status}, you can not start it. |
| 2910009 | calling {handler_name} failed with error message: {error}. |
| 2910010 | save task done status failed with error message: {error}. |
| 2910011 | task_info field is required for a multi-steps task. payload={payload}. |
| 2910012 | got NO task in channels: {channels}. |
| 2910013 | task {task_info} locked by another worker. |
| 2910014 | task {app_label}.{model_name}:{task_id} failed to save status with error message: {error}. |
| 2910015 | task_info field is required. |
| 2910016 | get task instance {task_info} failed with error: {error}. |
Releases
v0.0.1
- First release.
v0.0.4
- Fixed the problem that the task duplicately executed for the task queue is too long.
v0.0.5
- Fix do_task problem in actions.
- Fix ugettext_lazy problem.
- Fix problems in django 4.x.
v0.0.6
- Doc update.
v0.0.7
- Fix error message formatting problem.
v0.0.8
- Push to mq after instance-create-transaction committed.
v0.1.9
- Add SimpleTaskQueue and SimpleTaskChannel management.
v0.1.10
- Add Update Channel's Queue Size button for SimpleTaskChannelAdmin.
v0.1.12
- Do remove_duplicate_items_for_all_channels and update_channel_queue_size_for_all_channels at the end of do_auto_reset.
Metadata
Release files for django-simpletask2 0.1.12
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django-simpletask2-0.1.12.tar.gz | 22.3 kB | Without provenance | Details for django-simpletask2-0.1.12.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_simpletask2-0.1.12-py3-none-any.whl | Python 3 | none | any | Details for django_simpletask2-0.1.12-py3-none-any.whl |
Total release size: 50.0 kB
Release files / django-simpletask2-0.1.12.tar.gz
| Download URL | django-simpletask2-0.1.12.tar.gz |
|---|---|
| Size | 22.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0a7a6190834a450ca1ea434f53d9a235d06725ce440597ee09c07393f86652ed
|
|
BLAKE2b-256 checksum How to use checksums |
e7f30270d8eef9095a007558ae84129f3409d96e04551810933812a5148bef92
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.5
|
Release files / django_simpletask2-0.1.12-py3-none-any.whl
| Download URL | django_simpletask2-0.1.12-py3-none-any.whl |
|---|---|
| Size | 27.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cd506910d9996ec0fca727fd3e2c2db0fe77c8b3856cc10a36c2bb6b2c3f145e
|
|
BLAKE2b-256 checksum How to use checksums |
82ac4768b84317ef398f4f0238cc78ced063ef64b50d6426bd32a1110ba765ad
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.5
|
Security for django-simpletask2 0.1.12
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.