Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 22 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,17 @@ you also may have to setup some [mules](https://uwsgi-docs.readthedocs.org/en/la

## Installation

Simple execute `pip install uwsgi_tasks`
It's recommended to use `uv` for installation:

```bash
uv pip install uwsgi-tasks
```

Alternatively, you can use `pip`:

```bash
pip install uwsgi-tasks
```

## Usage

Expand Down Expand Up @@ -78,22 +88,22 @@ from uwsgi_tasks import task, TaskExecutor, SPOOL_OK, SPOOL_RETRY
def task_wrapper(func):
@wraps(func) # required!
def _inner(*args, **kwargs):
print 'Task started with parameters:', args, kwargs
print(f'Task started with parameters: {args} {kwargs}')
try:
func(*args, **kwargs)
except Exception as ex: # example
print 'Exception is occurred', ex, 'repeat the task'
print(f'Exception is occurred: {ex}, repeat the task')
return SPOOL_RETRY

print 'Task ended', func
print(f'Task ended: {func}')
return SPOOL_OK

return _inner

@task(executor=TaskExecutor.SPOOLER, retry_count=3, retry_timeout=5)
@task_wrapper
def spooler_task(text):
print 'Hello, spooler! text =', text
print(f'Hello, spooler! text = {text}')
raise Exception('Sorry, task failed!')
```

Expand Down Expand Up @@ -224,25 +234,25 @@ def print_every_5_seconds(signal_number):

Keep in mind: task is created on initialization.
"""
print 'Task for signal', signal_number
print(f'Task for signal {signal_number}')

@timer(seconds=5, iterations=3, target='workers')
def print_every_5_seconds(signal_number):
"""Prints string every 5 seconds 3 times"""
print 'Task with iterations for signal', signal_number
print(f'Task with iterations for signal {signal_number}')

@timer_lazy(seconds=5)
def print_every_5_seconds_after_call(signal_number):
"""Prints string every 5 seconds"""
print 'Lazy task for signal', signal_number
print(f'Lazy task for signal {signal_number}')

@cron(minute=-2)
def print_every_2_minutes(signal_number):
print 'Cron task:', signal_number
print(f'Cron task: {signal_number}')

@cron_lazy(minute=-2, target='mule')
def print_every_2_minutes_after_call(signal_number):
print 'Cron task:', signal_number
print(f'Cron task: {signal_number}')

...

Expand Down Expand Up @@ -310,9 +320,9 @@ from uwsgi_tasks import timer_lazy

@timer_lazy(target='worker')
def run_me_periodically(signal):
print('Running with signal:', signal)
print(f'Running with signal: {signal}')

def my_view(request):
run_me_periodically.add_setup(seconds=10, iterations=2)
run_me_periodically()
```
```
33 changes: 33 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[build-system]
requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"

[project]
name = "uwsgi-tasks"
version = "0.8.0"
authors = [
{ name="Oleg Churkin", email="bahusoff@gmail.com" },
]
description = "Asynchronous tasks management with UWSGI server"
readme = "README.md"
license = { file="LICENSE" }
requires-python = ">=3.8"
classifiers = [
"Development Status :: 5 - Production/Stable",
"Environment :: Web Environment",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Topic :: Software Development :: Libraries :: Python Modules",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
]
dependencies = [
"uwsgi",
]

[project.urls]
"Homepage" = "https://github.com/Bahus/uwsgi_tasks"
"Bug Tracker" = "https://github.com/Bahus/uwsgi_tasks/issues"
23 changes: 7 additions & 16 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,15 @@
# -*- coding: utf-8 -*-
from __future__ import print_function
import io
import sys
from setuptools import setup


if sys.argv[-1] == 'test':
# python-mock is required to run unit-tests
import unittest
unittest.main('uwsgi_tasks.tests', argv=sys.argv[:-1])


def get_long_description():
with io.open('./README.md', encoding='utf-8') as f:
readme = f.read()
return readme


setup(
name='uwsgi-tasks',
packages=['uwsgi_tasks'],
version='0.7.3',
version='0.8.0',
description='Asynchronous tasks management with UWSGI server',
author='Oleg Churkin',
author_email='bahusoff@gmail.com',
Expand All @@ -33,14 +22,16 @@ def get_long_description():
'Environment :: Web Environment',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
'Programming Language :: Python :: 3.13',
'Topic :: Software Development :: Libraries :: Python Modules',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License'
],
long_description=get_long_description(),
long_description_content_type='text/markdown',
requires=['uwsgi', 'six'],
install_requires=['six'],
)
requires=['uwsgi'],
install_requires=[],
)
9 changes: 5 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# pip install tox tox-pyenv
# pip install tox tox-uv
[tox]
envlist = {py27,py36,py37}
runner = uv
envlist = py311, py312, py313

[testenv]
commands=
python setup.py test
python -m unittest uwsgi_tasks.tests
deps =
mock
mock
15 changes: 13 additions & 2 deletions uwsgi_tasks/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
# -*- coding: utf-8 -*-
from uwsgi_tasks.tasks import (
Task, SignalTask, TimerTask, CronTask, TaskExecutor, set_uwsgi_callbacks,
RetryTaskException, SPOOL_OK, SPOOL_RETRY, SPOOL_IGNORE, get_current_task
)
from uwsgi_tasks.utils import django_setup
from uwsgi_tasks.decorators import *
from uwsgi_tasks.decorators import (
task, timer, timer_lazy, cron, cron_lazy, rbtimer, rbtimer_lazy, signal, signal_lazy
)

__all__ = [
# tasks
'Task', 'SignalTask', 'TimerTask', 'CronTask', 'TaskExecutor', 'set_uwsgi_callbacks',
'RetryTaskException', 'SPOOL_OK', 'SPOOL_RETRY', 'SPOOL_IGNORE', 'get_current_task',
# utils
'django_setup',
# decorators
'task', 'timer', 'timer_lazy', 'cron', 'cron_lazy', 'rbtimer', 'rbtimer_lazy', 'signal', 'signal_lazy',
]
Loading