Parsely is a framework for enqueuing messages via HTTP request for Celery.
Project description
Parsely is a framework for enqueuing messages via HTTP request for celery.
Example
tasks.py:
import parsely
p = parsely.Parsely('example', 'redis://localhost:6379/0')
celery = p.celery
def two_times(text: str) -> dict:
return {
'text': text * 2
}
@p.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. Parsely 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 parsely
import tasks # NOQA
application = parsely.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
producer receives your request
producer validates your message having text and the type is str or not. text`(str) is from typehint of
two_times
producer validates two_times returned value having text and the type is str or not. text`(str) is from typehint of
echo
producer put message
{"message":{"text":"HelloHello"}}
into queue.curl receives response.
Celery calls
echo
Extra
Preprocessor
preprocessor is optional. if you don’t need it, you can:
@p.task()
def echo(text: str) -> None:
print(text)
Also you can give multiple preprocessor:
@p.task(two_times, two_times)
def echo(text: str) -> None:
print(text)
logging
Parsely uses logger witch named “parsely”, so you can set log level like:
import logging
parsely_logger = logging.getLogger('parsely')
parsely_logger.setLevel(logging.DEBUG)
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
File details
Details for the file parsely-0.6.1.tar.gz
.
File metadata
- Download URL: parsely-0.6.1.tar.gz
- Upload date:
- Size: 11.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bebdf5b3653ecd5ee1b151663118bb1f450624afd069f26a79d18e3eda92d62b |
|
MD5 | 79667921284e92b9b3c4ef349f17a9d6 |
|
BLAKE2b-256 | dfe5c69a22c4e95a5ef5aef9e5986741b5425728c69e395a0f309da52aade0f5 |