Skip to content

Add API to name background tasks #387

@agritheory

Description

@agritheory

asyncio.create_task() from the standard library allows for identifying tasks with names. This seems particularly handy in case where you want to know about the status of a background task in Quart context and I think it'd be a nice feature to support. In the app that I'm currently working on, I'm using the background task to run an MQTT listener and logger, which can be configured via HTTP/GraphQL.

To ensure compatibility, I'd propose a check for 'name' in the kwargs and passing that to the task creation LOC

An example of how'd I'd like to be able to use this feature:

# called inside @app.before_serving 
async def mqtt_handler():
	broker_url = env.str("MQTT_BROKER_HOST", "localhost")
	broker_port = env.int("MQTT_BROKER_PORT", 1883)
	mqtt_logger = MQTTLogger(app.db, broker_url, broker_port)

	app.add_background_task(mqtt_logger.start, name="MQTTLoggerTask")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions