Skip to main content

Brokkoly is a framework for enqueuing messages via HTTP request for celery.

Project description

https://travis-ci.org/narusemotoki/brokkoly.svg?branch=master

Brokkoly is a framework for enqueuing messages via HTTP request for celery.

Example

tasks.py:

import brokkoly

b = brokkoly.Brokkoly('example', 'redis://localhost:6379/0')
celery = b.celery


def two_times(text: str) -> dict:
    return {
        'text': text * 2
    }


@b.task(two_times)
def echo(text: str) -> None:
    print(text)

two_times works as pre processor. It works before enqueing. It means it can return BadRequest to your client. Brokkoly validate message with typehint. Also you can have extra validation and any other process here.

Run celery -A tasks worker --loglevel=info

producer.py:

import brokkoly

import tasks  # NOQA

application = brokkoly.producer()

producer is WSGI application. You need to import your tasks for put message into queue.

Run with uWSGI uwsgi --http :8080 --wsgi-file producer.py --enable-threads --thunder-lock --master

Send Test Message!

curl -X POST -d '{"message":{"text": "Hello"}}' http://localhost:8080/example/echo

  1. producer receives your request

  2. producer validates your message having text and the type is str or not. text`(str) is from typehint of two_times

  3. producer validates two_times returned value having text and the type is str or not. text`(str) is from typehint of echo

  4. producer put message {"message":{"text":"HelloHello"}} into queue.

  5. curl receives response.

  6. Celery calls echo

Extra

preprocessor is optional. if you don’t need it, you can:

@b.task()
def echo(text: str) -> None:
    print(text)

Also you can give multiple preprocessor:

@b.task(two_times, two_times)
def echo(text: str) -> None:
    print(text)

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

brokkoly-0.0.1.tar.gz (3.7 kB view details)

Uploaded Source

File details

Details for the file brokkoly-0.0.1.tar.gz.

File metadata

  • Download URL: brokkoly-0.0.1.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for brokkoly-0.0.1.tar.gz
Algorithm Hash digest
SHA256 6b7bf350fbc75ba35d51279ef44a5bab41c462afa0ae7b52f2941bca3ab9a0fa
MD5 3bff0b522de82c54868c6f72a8abe9a4
BLAKE2b-256 f19658d9d5dde673cd37a34db633a1c6d73b74fc340f564be9a47c968f2f0902

See more details on using hashes here.

Provenance

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