Skip to main content

Build Status Test Coverage Maintainability Code style: black PyPI version

Logo

async-worker

O projeto tem como objetivo ser um framework para escrever workers assíncronos em python. Por worker entende-se qualquer aplicação que rode por tempo indeterminado e que receba estímulos de várias origens diferentes. Essas orignes podem ser:

  • Uma mensagem em um broker, como RabbitMQ;
  • Um evento recorrente gerado em um intervalo fixo de tempo;
  • Uma requisição HTTP
  • ...

Documentação: https://async-worker.github.io/async-worker/

Exemplos rápidos

Abaixo estão alguns exemplos bem simples que dão uma ideia do projeto e de como fica um código escrito com async-worker.

Handler HTTP

from aiohttp import web

from asyncworker import App

app = App()


@app.http.get(["/", "/other"])
async def handler():
    return web.json_response({})


app.run()

Esse handler recebe reqisições HTTP (GET) nos seguintes endereços (por padrão): http://127.0.0.1:8080/ e http://127.0.0.1:8080/other

Handler RabbitMQ

from typing import List

from asyncworker import App
from asyncworker.connections import AMQPConnection
from asyncworker.options import Options
from asyncworker.rabbitmq import RabbitMQMessage, AMQPRouteOptions

amqp_conn = AMQPConnection(
    hostname="127.0.0.1",
    username="guest",
    password="guest",
    prefetch_count=1024,
)

app = App(connections=[amqp_conn])


@app.amqp.consume(
    ["queue", "queue-2"], options=AMQPRouteOptions(bulk_size=512)
)
async def handler(messages: List[RabbitMQMessage]):
    print(f"Received {len(messages)} messages")
    for m in messages:
        await amqp_conn.put(
            data=m.body, exchange="other", routing_key="another-routing-key"
        )


@app.run_every(1)
async def produce(app: App):
    await amqp_conn.put(data={"msg": "ok"}, routing_key="queue")


app.run()

Esse handler recebe mensagens das filas queue e queue-2 em lotes de 512 mensagens. Se essas duas filas demorarem mais de 60 segundos para acumular, juntas, 1024 mensagens o handler será chamado imediatamente com a quantidade de mensagens que estiver disponível no momento.

O que esse handler está fazendo é apenas pegar todas as mensagens que ele recebe e enviar para o exchange="", routing_key="queue".


Logo created with DesignEvo logo maker

Metadata

Release files for async-worker 0.20.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 async-worker 0.20.2
File Size Uploaded Provenance
async-worker-0.20.2.tar.gz 36.6 kB Without provenance Details

Release files / async-worker-0.20.2.tar.gz

Download URL async-worker-0.20.2.tar.gz
Size 36.6 kB
Tags Source
SHA-256 checksum
How to use checksums
7790124701b6ecda09559a4d6a3246f039fa244efdc2abcad109eef526da62d7
BLAKE2b-256 checksum
How to use checksums
a57fa0be3884c5707776e0a9303b81c2b2ce3b88510b14d56c775ccd5dbf4815
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.4

Security for async-worker 0.20.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.

Release history Release notifications | RSS feed

This release

0.20.2 This release

1 release file 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