Skip to main content

No project description provided

Project description

spanreed

Message bus and task manager using redis streams.

Install

pip install spanreed

Configuration

Django configuration is supported. Alternatively, create a settings module and point SPANREED_SETTINGS_MOUDULE env variable to it.

Set SPANREED_REDIS_URL to your redis dsn.

Set SPANREED_MODELS to a list of import strings with your pydantic classes (see below), eg. SPANREED_MODELS = ('app.models.User', 'app.models.Permission').

Set SPANREED_PUBLISHER to your app name.

Set SPANREED_QUEUE to your environment name (eg. staging, prod).

Make sure all modules with tasks are imported at startup.

Message bus usage

Messages are broadcast to all listening apps. Use them to synchronize app state and implement "event sourcing" flows.

Create a message pydantic class by inheriting from spanreed.models.BaseMessage:

from spanreed.models import BaseMessage, Metadata

class UserCreated(BaseMessage):
    user_id: str

    def handle(self):
        print('got message', self)


user = UserCreated(user_id='id')
user.publish()

publish sends a message to the bus, handle is called by a daemon when a message is received.

Run the daemon with spanreed-consumer --queue-type message or manage.py spanreed_worker --queue-type message if using Django.

Task manager usage

Tasks are delivered only once inside a single app. Use them as celery replacement.

Create a task:

from spanreed import task

@task
def frobnicate_user(user_id):
    frobnicate(user_id)

frobnicate_user.dispatch('uid')

dispatch sends a task to the bus, which will be invoked by a daemon.

Run the daemon with spanreed-consumer --queue-type task or manage.py spanreed_worker --queue-type task if using Django.

Project details


Download files

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

Source Distribution

spanreed-0.1.tar.gz (15.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

spanreed-0.1-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

Details for the file spanreed-0.1.tar.gz.

File metadata

  • Download URL: spanreed-0.1.tar.gz
  • Upload date:
  • Size: 15.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for spanreed-0.1.tar.gz
Algorithm Hash digest
SHA256 db3104b11c7fdc343a33b5585bf8952a1d877f0033a451999fff7094cab89e56
MD5 06d8c4aa732ca3be9f59991c9e50499c
BLAKE2b-256 a00ffb1bb9aacf62be55a87c27b903bfd137fd55365c67e6d514db36dc1bf5c5

See more details on using hashes here.

Provenance

The following attestation bundles were made for spanreed-0.1.tar.gz:

Publisher: publish.yml on mbachry/spanreed

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file spanreed-0.1-py3-none-any.whl.

File metadata

  • Download URL: spanreed-0.1-py3-none-any.whl
  • Upload date:
  • Size: 11.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for spanreed-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b560793816e8c243c14c3a97dac9edaad4e9647a8f79ea1087df9930e2fd6ee7
MD5 4d1c2d337e150a4f677c30d1d0026491
BLAKE2b-256 faaaf281141768b51abbda54ccfffe345902dc39663e1bf9937c5012f703fe4f

See more details on using hashes here.

Provenance

The following attestation bundles were made for spanreed-0.1-py3-none-any.whl:

Publisher: publish.yml on mbachry/spanreed

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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