# 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.
### v0.3.7
- Fix ugettext problem.
Raw data
{
"_id": null,
"home_page": "",
"name": "django-simpletask",
"maintainer": "Zhang XianWei",
"docs_url": null,
"requires_python": "",
"maintainer_email": "zhangxianwei@zencore.cn",
"keywords": "django abstract model,django simple task",
"author": "Zhang XianWei",
"author_email": "zhangxianwei@zencore.cn",
"download_url": "https://files.pythonhosted.org/packages/af/db/ef4e3ee767bf2fea125376dcee1f4579b234096a93a7c7935947d7968d84/django-simpletask-0.3.7.tar.gz",
"platform": null,
"description": "# django-simpletask\n\nDjango application provides simple task model, admin, server services and client service.\n\n\n## Install\n\n```\npip install django-simpletask\n```\n\n## Usage\n\n**pro/settings**\n\n```\nINSTALLED_APPS = [\n 'django_db_lock',\n 'django_simpletask',\n]\n\nDJANGO_SIMPLETASK_ACLKEY = \"TsE9Jd3TrUtTA9wjGCLXoDqh891srpyo\"\n\n```\n\n**Note:**\n\n- Mostly you need a lock service, so we add django_db_lock in INSTALLED_APPS.\n- Set DJANGO_SIMPLETASK_ACLKEY to your own aclkey. It will be used in task executor.\n\n**app/models.py**\n\n```\nfrom django.db import models\nfrom django_simpletask.models import SimpleTask\n\nclass Task1(SimpleTask):\n title = models.CharField(max_length=64)\n\n class Meta:\n permissions = [] + SimpleTask.Meta.permissions\n\n def do_task_main(self):\n return \"done!\"\n\nclass Task2(SimpleTask):\n title = models.CharField(max_length=64)\n\n class Meta:\n permissions = [] + SimpleTask.Meta.permissions\n\n def do_task_main(self):\n return \"done!\"\n```\n\n\n**Note:**\n\n- Write your own task model based on SimpleTask.\n- Add task reset permission.\n- Implement you own do_task_main.\n\n**app/admin.py**\n\n```\nfrom django.contrib import admin\nfrom django_simpletask.admin import SimpleTaskAdmin\nfrom .models import Task1\nfrom .models import Task2\n\n\nclass TaskAdmin(SimpleTaskAdmin, admin.ModelAdmin):\n list_display = [\"title\"] + SimpleTaskAdmin.list_display\n\n\nadmin.site.register(Task1, TaskAdmin)\nadmin.site.register(Task2, TaskAdmin)\n\n```\n\n**Note:**\n\n- Mostly we don't want to change anything inside task, so we set task fields readonly.\n\n**task_executor.py**\n\n```\nfrom daemon_application.app import DaemonApplication\nfrom django_simpletask.services import SimpleTaskService\n\nclass TaskExcutor(DaemonApplication):\n def main(self):\n service = SimpleTaskService(\"http://127.0.0.1:8000/example/task/services/\", aclkey=\"TsE9Jd3TrUtTA9wjGCLXoDqh891srpyo\")\n service.start()\n service.join()\n\napp = TaskExcutor().get_controller()\n\nif __name__ == \"__main__\":\n app()\n\n```\n\n**Note:**\n\n- Add task_executor.py script.\n- Set the server to your own url.\n- Set the aclkey match the DJANGO_SIMPLETASK_ACLKEY setting.\n\n## Release\n\n### v0.1.0\n\n- First release.\n- Take from django-fastadmin. django-fastadmin should forcus on admin extensions, but NOT abstract models.\n\n### v0.1.1\n\n- Add SimpleTask.do_tasks.\n\n### v0.1.2\n\n- Add SimpleTask.serve and SimpleTask.serve_forever.\n\n### v0.1.3\n\n- Add idle_sleep_time parameter for SimpleTask.serve_forever.\n\n### v0.1.6\n\n- Add reset action.\n- Add SimpleTask.force_finish.\n- Add multi-threads serve.\n\n### v0.2.2\n\n- Long running service don't use database.\n- Add aclkey check for simpletask apis.\n\n### v0.2.8\n\n- Add SimpleTaskServiceProxy and required views.\n- Add get_ready_tasks_queryset to SimpleTaskViews.\n\n### v0.2.9\n\n- Add channel params.\n\n### v0.3.5\n\n- Bad response handler.\n- Services changed a a lot.\n\n### v0.3.6\n\n- Doc update.\n\n### v0.3.7\n\n- Fix ugettext problem.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Django application provides simple task model, admin, server services and client service.",
"version": "0.3.7",
"project_urls": null,
"split_keywords": [
"django abstract model",
"django simple task"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "d654bafaa25dd71fd095dd77c6a10e4e7a17b71aac80d458f3456ae62c9bc471",
"md5": "183817710381e0615ffff16505c10763",
"sha256": "3c15a2251ffe9d392075ee6ff4994421c2fbdce323dcd0ac81818d11eaa897fe"
},
"downloads": -1,
"filename": "django_simpletask-0.3.7-py3-none-any.whl",
"has_sig": false,
"md5_digest": "183817710381e0615ffff16505c10763",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 16126,
"upload_time": "2023-09-22T02:26:11",
"upload_time_iso_8601": "2023-09-22T02:26:11.696095Z",
"url": "https://files.pythonhosted.org/packages/d6/54/bafaa25dd71fd095dd77c6a10e4e7a17b71aac80d458f3456ae62c9bc471/django_simpletask-0.3.7-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "afdbef4e3ee767bf2fea125376dcee1f4579b234096a93a7c7935947d7968d84",
"md5": "d70093c9fec255f7ac00f050c8ed90c9",
"sha256": "ce816d92547bca9f9efb25accdfe1abd8e07c3ab0160c661d19558764af71859"
},
"downloads": -1,
"filename": "django-simpletask-0.3.7.tar.gz",
"has_sig": false,
"md5_digest": "d70093c9fec255f7ac00f050c8ed90c9",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 14281,
"upload_time": "2023-09-22T02:26:13",
"upload_time_iso_8601": "2023-09-22T02:26:13.098702Z",
"url": "https://files.pythonhosted.org/packages/af/db/ef4e3ee767bf2fea125376dcee1f4579b234096a93a7c7935947d7968d84/django-simpletask-0.3.7.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-09-22 02:26:13",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "django-simpletask"
}