Skip to main content

Runner framework for aiohttp

Project description

Static Badge PyPI - Version PyPI - License codecov Static Badge Static Badge

Run jobs in the background of an aiohttp server.

Usage

Define a service

import asyncio
from some_aiohttp_service import BaseService

async def some_long_calculation(a, b):
    await asyncio.sleep(5)
    return f"Done with {a}/{b}"

class TestService(BaseService):
    name = "test"

    @staticmethod
    async def work(job):
        return await some_long_calculation(**job.data)

    async def error_handler(self, job, error):
        print("Error", error)

    async def result_handler(self, job, result):
        print(result)

Set up an aiohttp server:

from aiohttp.web import Application, get, run_app
from aiohttp.web_exceptions import HTTPOk, HTTPAccepted

async def health(_):
    raise HTTPOk

async def hello(request):
    a = request.match_info["a"]
    b = request.match_info["b"]
    await request.app["test"].commit_work({"a": a, "b": b})
    raise HTTPAccepted

app = Application()
app.add_routes([get("/work/{a}/{b}", hello), get("/health", health)])

app.cleanup_ctx.append(TestService(app).init)

run_app(app)

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

some_aiohttp_service-0.1.7.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

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

some_aiohttp_service-0.1.7-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file some_aiohttp_service-0.1.7.tar.gz.

File metadata

  • Download URL: some_aiohttp_service-0.1.7.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for some_aiohttp_service-0.1.7.tar.gz
Algorithm Hash digest
SHA256 65744c88fad048c161064ef809e9f0efdcbc077a99534ccc468773fe9a582048
MD5 c0e599b55fd9131b1d7982513ec81ace
BLAKE2b-256 b12bb690f5ebb3ea3fa1279739feb602a90760eea6b998e1af13703b58bf985f

See more details on using hashes here.

Provenance

The following attestation bundles were made for some_aiohttp_service-0.1.7.tar.gz:

Publisher: ci.yml on tommmlij/some-aiohttp-service

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

File details

Details for the file some_aiohttp_service-0.1.7-py3-none-any.whl.

File metadata

File hashes

Hashes for some_aiohttp_service-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 4261448724f5719ed514b59fb8cf90dfb5392018657a643087d71edb02b8f11c
MD5 1c92b9f6ad55c36581b37ebf0d5be45b
BLAKE2b-256 9c8fae0ec60d46557036b5037c70f2a38d0fb36dc07aa0427e9d8bc155e494bf

See more details on using hashes here.

Provenance

The following attestation bundles were made for some_aiohttp_service-0.1.7-py3-none-any.whl:

Publisher: ci.yml on tommmlij/some-aiohttp-service

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