Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add API to name background tasks #387

Open
agritheory opened this issue Nov 16, 2024 · 0 comments
Open

Add API to name background tasks #387

agritheory opened this issue Nov 16, 2024 · 0 comments

Comments

@agritheory
Copy link
Contributor

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")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant