diff options
author | CoprDistGit <infra@openeuler.org> | 2023-05-18 05:46:28 +0000 |
---|---|---|
committer | CoprDistGit <infra@openeuler.org> | 2023-05-18 05:46:28 +0000 |
commit | 72652a6e0f56750e605200fadb2ac9a65eae8d56 (patch) | |
tree | 11053456b44e57b97bfcbe13d6a84388c7394170 /python-django-workers.spec | |
parent | 4ccbfc0f40e18afac9f32040ad61ee454a893e21 (diff) |
automatic import of python-django-workers
Diffstat (limited to 'python-django-workers.spec')
-rw-r--r-- | python-django-workers.spec | 411 |
1 files changed, 411 insertions, 0 deletions
diff --git a/python-django-workers.spec b/python-django-workers.spec new file mode 100644 index 0000000..135e799 --- /dev/null +++ b/python-django-workers.spec @@ -0,0 +1,411 @@ +%global _empty_manifest_terminate_build 0 +Name: python-django-workers +Version: 0.2.0 +Release: 1 +Summary: Simple background tasks for Django +License: MIT License +URL: https://github.com/geekforbrains/django-workers +Source0: https://mirrors.nju.edu.cn/pypi/web/packages/22/3c/b71880877ee33cea97f89ae8c6088b0bbaf9a0e05cfa3d2625abcf207d0f/django-workers-0.2.0.tar.gz +BuildArch: noarch + + +%description +# Django Workers + +A simple background task worker that uses your Django database and admin for management. This +project is meant for small to medium scale uses. If you need something more, check out Celery. + + +## Install + +Download the package + +``` +pip install django-workers +``` + +and add it to your Django installed apps + +```python +INSTALLED_APPS = [ + # ... + 'workers', + # ... +] +``` + +## Basics + +Create a `tasks.py` file in the Django app you'd like to have tasks in. These tasks will automatically +become available thanks to autodiscovery. + +```python +from workers import task + +@task() +def say_hello(name): + print('Howdy', name) +``` + +### Calling tasks + +Tasks become simple Python callables. Calling them inserts that task to your Django database and +waits for a worker to pick it up. + +```python +say_hello('Foo') # Sent to background automatically +``` + +### Running the workers + +Now boot-up your workers to crunch some data. Workers poll the Database for new tasks they should +work on. + +``` +python manage.py runworkers +``` + + +## Scheduled tasks + +Sometimes you want to run a specific task every X seconds or at a later date. Thats what scheduled +tasks are for. + +### Repeating scheduled tasks + +Tasks specified with a schedule in seconds will repeat. + +```python +from workers import task + +@task(schedule=10) +def do_something(): + print('I run every 10 seconds') + +@task(schedule=60*5) +def do_something_later(): + print('I run every 5 minutes') + +@task(schedule=60*60*8) +def do_something_even_later(): + print('I run every 8 hours') +``` + +### Date scheduled tasks + +Tasks can be scheduled to *run once* at a later date by passing a `_schedule=<datetime>` argument +when the task is called. + +```python +from datetime import datetime, timedelta +from workers import task + +trial_end_date = datetime.utcnow() + timedelta(days=14) + +@task() +def trial_ending(): + send_email('Your trial is ending!') + +# Specifying the `schedule` argument will tell the worker when this task should run +trial_ending(_schedule=trial_end_date) +``` + +## Settings + +You can optionally override these settings in your Django `settings.py` file: + +- `WORKERS_SLEEP` (default 5) - Wait in seconds before checking for tasks, if none were found +- `WORKERS_PURGE` (default 1,000) - How many recent task logs to keep in the admin + +#### TODO (not working) +- `WORKERS_TIMEOUT` (default 30) - Seconds a task can run before its killed +- `WORKERS_RETRY` (default 3) - Number of retries before giving up +- `WORKERS_CONCURRENCY` (default 1) - Number of worker processes to run + + + + +%package -n python3-django-workers +Summary: Simple background tasks for Django +Provides: python-django-workers +BuildRequires: python3-devel +BuildRequires: python3-setuptools +BuildRequires: python3-pip +%description -n python3-django-workers +# Django Workers + +A simple background task worker that uses your Django database and admin for management. This +project is meant for small to medium scale uses. If you need something more, check out Celery. + + +## Install + +Download the package + +``` +pip install django-workers +``` + +and add it to your Django installed apps + +```python +INSTALLED_APPS = [ + # ... + 'workers', + # ... +] +``` + +## Basics + +Create a `tasks.py` file in the Django app you'd like to have tasks in. These tasks will automatically +become available thanks to autodiscovery. + +```python +from workers import task + +@task() +def say_hello(name): + print('Howdy', name) +``` + +### Calling tasks + +Tasks become simple Python callables. Calling them inserts that task to your Django database and +waits for a worker to pick it up. + +```python +say_hello('Foo') # Sent to background automatically +``` + +### Running the workers + +Now boot-up your workers to crunch some data. Workers poll the Database for new tasks they should +work on. + +``` +python manage.py runworkers +``` + + +## Scheduled tasks + +Sometimes you want to run a specific task every X seconds or at a later date. Thats what scheduled +tasks are for. + +### Repeating scheduled tasks + +Tasks specified with a schedule in seconds will repeat. + +```python +from workers import task + +@task(schedule=10) +def do_something(): + print('I run every 10 seconds') + +@task(schedule=60*5) +def do_something_later(): + print('I run every 5 minutes') + +@task(schedule=60*60*8) +def do_something_even_later(): + print('I run every 8 hours') +``` + +### Date scheduled tasks + +Tasks can be scheduled to *run once* at a later date by passing a `_schedule=<datetime>` argument +when the task is called. + +```python +from datetime import datetime, timedelta +from workers import task + +trial_end_date = datetime.utcnow() + timedelta(days=14) + +@task() +def trial_ending(): + send_email('Your trial is ending!') + +# Specifying the `schedule` argument will tell the worker when this task should run +trial_ending(_schedule=trial_end_date) +``` + +## Settings + +You can optionally override these settings in your Django `settings.py` file: + +- `WORKERS_SLEEP` (default 5) - Wait in seconds before checking for tasks, if none were found +- `WORKERS_PURGE` (default 1,000) - How many recent task logs to keep in the admin + +#### TODO (not working) +- `WORKERS_TIMEOUT` (default 30) - Seconds a task can run before its killed +- `WORKERS_RETRY` (default 3) - Number of retries before giving up +- `WORKERS_CONCURRENCY` (default 1) - Number of worker processes to run + + + + +%package help +Summary: Development documents and examples for django-workers +Provides: python3-django-workers-doc +%description help +# Django Workers + +A simple background task worker that uses your Django database and admin for management. This +project is meant for small to medium scale uses. If you need something more, check out Celery. + + +## Install + +Download the package + +``` +pip install django-workers +``` + +and add it to your Django installed apps + +```python +INSTALLED_APPS = [ + # ... + 'workers', + # ... +] +``` + +## Basics + +Create a `tasks.py` file in the Django app you'd like to have tasks in. These tasks will automatically +become available thanks to autodiscovery. + +```python +from workers import task + +@task() +def say_hello(name): + print('Howdy', name) +``` + +### Calling tasks + +Tasks become simple Python callables. Calling them inserts that task to your Django database and +waits for a worker to pick it up. + +```python +say_hello('Foo') # Sent to background automatically +``` + +### Running the workers + +Now boot-up your workers to crunch some data. Workers poll the Database for new tasks they should +work on. + +``` +python manage.py runworkers +``` + + +## Scheduled tasks + +Sometimes you want to run a specific task every X seconds or at a later date. Thats what scheduled +tasks are for. + +### Repeating scheduled tasks + +Tasks specified with a schedule in seconds will repeat. + +```python +from workers import task + +@task(schedule=10) +def do_something(): + print('I run every 10 seconds') + +@task(schedule=60*5) +def do_something_later(): + print('I run every 5 minutes') + +@task(schedule=60*60*8) +def do_something_even_later(): + print('I run every 8 hours') +``` + +### Date scheduled tasks + +Tasks can be scheduled to *run once* at a later date by passing a `_schedule=<datetime>` argument +when the task is called. + +```python +from datetime import datetime, timedelta +from workers import task + +trial_end_date = datetime.utcnow() + timedelta(days=14) + +@task() +def trial_ending(): + send_email('Your trial is ending!') + +# Specifying the `schedule` argument will tell the worker when this task should run +trial_ending(_schedule=trial_end_date) +``` + +## Settings + +You can optionally override these settings in your Django `settings.py` file: + +- `WORKERS_SLEEP` (default 5) - Wait in seconds before checking for tasks, if none were found +- `WORKERS_PURGE` (default 1,000) - How many recent task logs to keep in the admin + +#### TODO (not working) +- `WORKERS_TIMEOUT` (default 30) - Seconds a task can run before its killed +- `WORKERS_RETRY` (default 3) - Number of retries before giving up +- `WORKERS_CONCURRENCY` (default 1) - Number of worker processes to run + + + + +%prep +%autosetup -n django-workers-0.2.0 + +%build +%py3_build + +%install +%py3_install +install -d -m755 %{buildroot}/%{_pkgdocdir} +if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi +if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi +if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi +if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi +pushd %{buildroot} +if [ -d usr/lib ]; then + find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/lib64 ]; then + find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/bin ]; then + find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/sbin ]; then + find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst +fi +touch doclist.lst +if [ -d usr/share/man ]; then + find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst +fi +popd +mv %{buildroot}/filelist.lst . +mv %{buildroot}/doclist.lst . + +%files -n python3-django-workers -f filelist.lst +%dir %{python3_sitelib}/* + +%files help -f doclist.lst +%{_docdir}/* + +%changelog +* Thu May 18 2023 Python_Bot <Python_Bot@openeuler.org> - 0.2.0-1 +- Package Spec generated |