{"id":16419720,"url":"https://github.com/ericls/django-simple-task","last_synced_at":"2025-03-16T17:34:10.176Z","repository":{"id":36904436,"uuid":"230701506","full_name":"ericls/django-simple-task","owner":"ericls","description":"Simple background task for Django 3","archived":false,"fork":false,"pushed_at":"2022-12-08T07:42:04.000Z","size":114,"stargazers_count":87,"open_issues_count":5,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-12T07:25:46.051Z","etag":null,"topics":["asgi","django","hacktoberfest","python","task-runner"],"latest_commit_sha":null,"homepage":"https://django-simple-task.rtfd.org","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ericls.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-12-29T04:17:03.000Z","updated_at":"2024-01-29T05:13:23.000Z","dependencies_parsed_at":"2023-01-17T07:06:22.697Z","dependency_job_id":null,"html_url":"https://github.com/ericls/django-simple-task","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericls%2Fdjango-simple-task","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericls%2Fdjango-simple-task/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericls%2Fdjango-simple-task/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericls%2Fdjango-simple-task/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ericls","download_url":"https://codeload.github.com/ericls/django-simple-task/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221666406,"owners_count":16860415,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["asgi","django","hacktoberfest","python","task-runner"],"created_at":"2024-10-11T07:25:43.723Z","updated_at":"2024-10-27T10:58:58.821Z","avatar_url":"https://github.com/ericls.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Django Simple Task\n[![Github Actions](https://github.com/ericls/django-simple-task/workflows/Build/badge.svg)](https://github.com/ericls/django-simple-task/actions)\n[![Documentation Status](https://readthedocs.org/projects/django-simple-task/badge/?version=latest)](https://django-simple-task.readthedocs.io/?badge=latest)\n[![Code Coverage](https://codecov.io/gh/ericls/django-simple-task/branch/master/graph/badge.svg)](https://codecov.io/gh/ericls/django-simple-task)\n[![Python Version](https://img.shields.io/badge/Python-3.7%20|%203.8|%203.9-%231081c1)](https://pypi.org/project/django-simple-task/)\n[![PyPI Package](https://img.shields.io/pypi/v/django-simple-task.svg)](https://pypi.org/project/django-simple-task/)\n[![License](https://img.shields.io/pypi/l/django-simple-task.svg)](https://github.com/ericls/django-simple-task/blob/master/LICENSE)\n\n`django-simple-task` runs background tasks in Django 3 without requiring other services and workers. It runs them in the same event loop as your ASGI application. It is not resilient as a proper task runner such as Celery, but works for some simple tasks and has less overall overheads.\n\n## Requirements\n`django-simple-task` expect ASGI lifespan protocol to be supported by the server. Currently Daphne does not support this.\n\nThis package is tested with:\n - Python 3.7, 3.8 and 3.9,\n - Django 3.1 and 3.2.\n\n## Guide\n\nInstall the package:\n```bash\npip install django-simple-task\n```\n\nAdded it to installed apps:\n```python\n# settings.py\nINSTALLED_APPS = [\n\t...\n\t'django_simple_task'\n]\n```\nApply ASGI middleware :\n```python\n# asgi.py\nfrom django_simple_task import django_simple_task_middlware\napplication = django_simple_task_middlware(application)\n```\n\nCall a background task in Django view:\n```python\nfrom django_simple_task import defer\n\ndef task1():\n\ttime.sleep(1)\n\tprint(\"task1 done\")\n\nasync def task2():\n\tawait asyncio.sleep(1)\n\tprint(\"task2 done\")\n\ndef view(requests):\n\tdefer(task1)\n\tdefer(task2)\n\treturn HttpResponse(b\"My View\")\n```\n\nIt is required to run Django with ASGI server. [Official Doc](https://docs.djangoproject.com/en/3.0/howto/deployment/asgi/)\n\n## Configurations\n\nConcurrency level can be controlled by adding `DJANGO_SIMPLE_TASK_WORKERS` to settings. Defaults to `1`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fericls%2Fdjango-simple-task","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fericls%2Fdjango-simple-task","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fericls%2Fdjango-simple-task/lists"}