-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.py
More file actions
33 lines (26 loc) · 693 Bytes
/
main.py
File metadata and controls
33 lines (26 loc) · 693 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from fastapi import FastAPI
from redis import Redis
from rq import Queue
from pydantic import BaseModel
from job import print_number
app = FastAPI()
redis_conn = Redis(host="localhost", port=6379)
task_queue = Queue("task_queue", connection=redis_conn)
class JobData(BaseModel):
lowest : int
highest: int
@app.get("/")
def index():
return {
"success": True,
"message": "pong"
}
@app.post("/job")
def post_job(job: JobData):
lowest = job.lowest
highest = job.highest
job_instance = task_queue.enqueue(print_number, lowest, highest)
return {
"success": True,
"job_id": job_instance.id
}