Skip to main content

Muffin-Donald

Muffin-Donald is a plugin for the Muffin framework that provides support for asynchronous background tasks, workers, and scheduling.

Tests Status PyPI Version Python Versions

Features

  • ✅ Register async tasks
  • ✅ Run background workers
  • ✅ Schedule periodic tasks (cron or intervals)
  • ✅ RPC-style submit and wait for result
  • ✅ Muffin plugin integration with lifecycle management

Requirements

  • python >= 3.11
  • muffin >= 0.60.0
  • donald >= 0.1.0

Installation

pip install muffin-donald

Usage

Initialize the plugin:

import muffin
from muffin_donald import Plugin

app = muffin.Application("example")

tasks = Plugin(app, backend="redis", backend_params={
    "url": "redis://localhost:6379/0"
}, start_worker=True, start_scheduler=True)

Register a task:

@tasks.task()
async def my_task(x, y):
    return x + y

Submit task for background execution:

my_task.submit(1, 2)

Submit and wait for result (RPC style):

result = await my_task.submit_and_wait(1, 2)
print("Result:", result)  # Result: 3

Schedule a periodic task:

@tasks.task()
async def periodic_task():
    print("Periodic task executed")

periodic_task.schedule("*/5 * * * *")  # every 5 minutes

Handle task errors with on_error:

@tasks.on_error
async def handle_error(exc):
    print("Task error:", exc)

Lifecycle hooks:

@tasks.on_start
async def startup():
    print("Tasks manager started")

@tasks.on_stop
async def shutdown():
    print("Tasks manager stopped")

Healthcheck commands:

muffin <app> tasks-worker-health
muffin <app> tasks-scheduler-health
  • Returns exit code 0 if healthy
  • Returns exit code 1 if unhealthy

Commands

Command Description
tasks-worker Run the worker process
tasks-scheduler Run the scheduler
tasks-worker-health Check worker health
tasks-scheduler-health Check scheduler health

Configuration Options

You can configure the plugin via parameters or Muffin settings (with TASKS_ prefix):

Name Default Description
log_level INFO Logger level
log_config None Logger config
backend memory Backend: memory, redis, amqp
backend_params {} Backend connection params
worker_params {} Worker params
start_worker False Auto start a worker on startup
start_scheduler False Auto start a scheduler on startup

Example in Muffin settings:

TASKS_BACKEND = "redis"
TASKS_BACKEND_PARAMS = {"url": "redis://localhost:6379/0"}
TASKS_START_WORKER = True
TASKS_START_SCHEDULER = True

Testing

Example using manage_lifespan:

import pytest
from asgi_tools.tests import manage_lifespan

async def test_tasks(app, tasks):
    async with manage_lifespan(app):
        result = await my_task.submit_and_wait(1, 2)
        assert result == 3

Bug Tracker

Please report issues or suggestions at https://github.com/klen/muffin-donald/issues

Contributing

Development happens at: https://github.com/klen/muffin-donald

Contributors

  • klen (Kirill Klenov)

License

Licensed under the MIT license.

Metadata

Release files for muffin-donald 2.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for muffin-donald 2.1.2
File Size Uploaded Provenance Actions
muffin_donald-2.1.2.tar.gz 5.0 kB Without provenance Details for muffin_donald-2.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for muffin-donald 2.1.2
File Interpreter ABI Platform Actions
muffin_donald-2.1.2-py3-none-any.whl Python 3 none any Details for muffin_donald-2.1.2-py3-none-any.whl

Total release size: 9.7 kB

Release files / muffin_donald-2.1.2.tar.gz

Download URL muffin_donald-2.1.2.tar.gz
Size 5.0 kB
Tags Source
SHA-256 checksum
How to use checksums
af6109ece919a9ba83dff66220da42877c135505c33647f98a38875e23c7ac2a
BLAKE2b-256 checksum
How to use checksums
9db45fe3c9f61856852da18f94c730097a1c3bb5afa1bfb188bb16c7ed97938a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / muffin_donald-2.1.2-py3-none-any.whl

Download URL muffin_donald-2.1.2-py3-none-any.whl
Size 4.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e09fc635747a89b75b108a6ca91889cb73db21d05f41ccd67f6c9848e24b2b0b
BLAKE2b-256 checksum
How to use checksums
931145935b327e32c2df6db2dae524778e22610bb42447722c50e476c520c704
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for muffin-donald 2.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

2.1.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page