Skip to main content

Donald is here

Project description

Donald – A fast and simple tasks manager for Asyncio.

Donald supports synchronous and asynchronous paradigms. The package is running coroutines and functions in multi loops. Donald could run periodic tasks and listen AMQP queues.

Tests Status PYPI Version Python Versions

Requirements

  • python 3.8+

Installation

Donald should be installed using pip:

pip install donald

With redis support:

pip install donald[redis]

Quick Start

Init the tasks manager:

# Init Donald
manager = Donald(

    # Params (default values)
    # -----------------------

    # Setup logging
    log_level=logging.INFO,
    log_config=None,

    # Choose a backend (memory|redis|amqp)
    # memory - is only recommended for testing/local development
    backend='memory',

    # Backend connection params
    # redis: {'url': 'redis://localhost:6379/0', 'channel': 'donald'}
    # amqp: {'url': 'amqp://guest:guest@localhost:5672/', 'queue': 'donald', 'exchange': 'donald'}
    backend_params={},

    # Tasks worker params
    worker_params={
      # Max tasks in work
      'max_tasks': 0,

      # Tasks default params (delay, timeout)
      'task_defaults': {},

      # A awaitable function to run on worker start
      'on_start': None

      # A awaitable function to run on worker stop
      'on_stop': None

      # A awaitable function to run on worker error
      'on_error': None

    },
)

# Wrap a function to task
@manager.task
async def myfunc(*args, **kwargs):
    # Do some job here

# Start the manager somewhere (on app start for example)
await manager.start()

# you may run a worker in the same process
# not recommended for production
worker = manager.create_worker()
worker.start()

# ...

# Submit the task to workers
myfunc.submit(*args, **kwargs)

# ...

# Stop the manager when you need
await worker.stop()
await manager.stop()

Schedule tasks

@tasks.schedule('*/5 * * * *')  # Supports cron expressions, number of seconds, timedelta
@tasks.task
async def myfunc(*args, **kwargs):
    """Run every 5 minutes"""
    # Do some job here


# you may run a scheduler in the same process
# not recommended for production
manager.scheduler.start()

# ...

# Stop the scheduler before stop the tasks manager
manager.scheduler.stop()

Run in production

Create a tasks manager somewhere in your app tasks.py:

manager = Donald(backend='amqp')

# Setup your tasks and schedules.
# See the Quick Start section for details.

Run a worker in a separate process:

$ donald -M tasks.manager worker

Run a scheduler (if you need) in a separate process:

$ donald -M tasks.manager scheduler

Bug tracker

If you have any suggestions, bug reports or annoyances please report them to the issue tracker at https://github.com/klen/donald/issues

Contributing

Development of starter happens at github: https://github.com/klen/donald

License

Licensed under a BSD license.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

donald-0.31.0.tar.gz (11.4 kB view details)

Uploaded Source

Built Distribution

donald-0.31.0-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

Details for the file donald-0.31.0.tar.gz.

File metadata

  • Download URL: donald-0.31.0.tar.gz
  • Upload date:
  • Size: 11.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.14

File hashes

Hashes for donald-0.31.0.tar.gz
Algorithm Hash digest
SHA256 a0bf65d11e3e49c67a0bef99e2ab5ef82e5923c62630c352d638c8fa61d54df9
MD5 a05d1434ce59f06d1397de19b1bfd0f1
BLAKE2b-256 1e5d7e333ee8aaa56dabe0c091868079091816597df7802772a8851810a7f8e8

See more details on using hashes here.

File details

Details for the file donald-0.31.0-py3-none-any.whl.

File metadata

  • Download URL: donald-0.31.0-py3-none-any.whl
  • Upload date:
  • Size: 12.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.14

File hashes

Hashes for donald-0.31.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c4d8179820a0ffaf57facd1ec0a32068b34ac8e0bdb737d0b16bc966d55de61f
MD5 c480de9bdf2be2e4f679f7ff0e20aa83
BLAKE2b-256 dbd8515eafe306b43049c2bb976227f8e96de013582b8b3dc8ef9dca64528e7e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page