Add API to name background tasks

Aperta
#387 1 commento 2 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
48/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
python
Ambito
backend

Direzione di ricerca

Inizia in src/quart/app.py, nell’implementazione di app.add_background_task intorno alle righe collegate, e confronta la creazione del task con asyncio.create_task(). Supporta un argomento name opzionale mantenendo gli usi esistenti senza di esso; il lavoro è completato quando l’API dei task in background accetta l’utilizzo di esempio e passa name.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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")
Lingua principale
Python
Stelle
3.7k
Fork
209
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di pallets/quart

Tutte le issue di pallets/quart

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.