How can I run schedule inside a docker container that is also running Flask to serve API requests?
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 25/100
Direzione di ricerca
Non viene indicato alcun file del repository, test o punto di ingresso; l’issue fornisce solo un esempio Python con schedule.run_pending e descrive i vincoli di Flask, Docker e AWS. Inizia esaminando questo loop e il requisito di un singolo container, quindi determina se le attività pianificate non bloccanti e di lunga durata richieste sono supportate; per considerarlo completato sarebbe necessario un approccio funzionante e chiaramente documentato.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
I have python / Flask running in a Docker container deployed to a cloud service (AWS).
It responds to HTTP API requests (GET, POST)
Everything is working fine there with this.
Now I want to implement some recurring tasks that run inside the container using any Python scheduler or cron like package.
The recurring tasks may take 30 mins or an hour and will be running inside the container in parallel with responding to API requests without interruption.
I stumbled upon a Python library called 'schedule' (import schedule) and some sample code here
https://github.com/dbader/schedule
import schedule
from datetime import datetime
def job():
print('\n---\njob()')
now = datetime.now()
current_time = now.strftime("%H:%M:%S")
print("Current Time =", current_time)
print("I'm working...")
schedule.every(10).seconds.do(job)
while True:
schedule.run_pending()
time.sleep(10)
You can see the problem here where the package requires a while True: loop If that is running when the container is instantiated, (in the loop always), the container will not respond to API requests.
Is there another scheduling package that does not require a dedicated loop running all the time?
It seems like I need something external that sleeps for so many seconds and then makes an API call to the container that would invoke:
schedule.run_pending()
but even then, this will not work because the job() running within an API call ( a long running task ), may take 30 mins to 1 hour to run and hit an HTTP time out.
How can I have an API server that responds to API requests, but also runs internally long running tasks initiated by an internal scheduler in the container?
I am not running under an EC2 or GCE instance where traditional cron can be used. I am using a service that simply hosts and runs a single container.
Requirements:
- Docker container API server that responds to HTTP requests (GET, POST)
- has the ability to run any number of tasks on a schedule that may be long running where the container will stay active and not be shut down or moved out of the cloud hosting service that is running it.
If you have actually done this and have done this with a working solution, please respond.
- Lingua principale
- Python
- Stelle
- 12.3k
- Fork
- 1k
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di dbader/schedule
-
run_all sleeps after the final job despite documenting delays between jobsForse già presa @Gambit-Checkmate l’ha presa 12 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
-
[CRASH CONDITION] - Guard self.unit against NoneForse già presa @worksbyfriday l’ha presa 253 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 65/100
-
Bug when DST endsAperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 25/100
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
Tutte le issue di dbader/schedule
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
microsoft/agent-lightning#661 ·
I maintainer di solito rispondono entro 2 giorni
-
area/profiles comp/cli P3 type/feature
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
NousResearch/hermes-agent#146372 ·
I maintainer di solito rispondono entro 1 giorno
-
[BUG] OpenAI-compatible embedding model alias breaks embedder constructionForse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
I maintainer di solito rispondono entro 1 giorno
-
[oblt-aw][autodoc] Document obs-aw-automerge contract and fix automerge doc inconsistenciesForse già presa @github-actions l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno
-
GeoSeries scale and skew tests fail with pytest 9.2.0Forse già presa @jiayuasu l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno