-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.py
49 lines (37 loc) · 1.43 KB
/
main.py
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from fastapi import FastAPI, Request
from fastapi.responses import HTMLResponse, JSONResponse
import celery_app
app = FastAPI()
@app.get("/")
def home(request: Request):
return HTMLResponse(
f"""
<html>
<head>
<title>Celery on AWS ECS examples</title>
</head>
<body>
<div><a href="{request.url_for('send_newsletter')}">Send newsletter - Single Job</a></div>
<div><a href="{request.url_for('send_newsletter_fanout')}">Send newsletter - Fan-out</a></div>
<div><a href="{request.url_for('send_newsletter_batching')}">Send newsletter - Batching</a></div>
<div><a href="{request.url_for('send_newsletter_locking')}">Send newsletter - Locking</a></div>
</body>
</html>
"""
)
@app.get("/send-newsletter")
def send_newsletter():
task = celery_app.send_newsletter.apply_async()
return JSONResponse({"task_id": task.id})
@app.get("/send-newsletter/fan-out")
def send_newsletter_fanout():
task = celery_app.send_newsletter_fan_out.apply_async()
return JSONResponse({"task_id": task.id})
@app.get("/send-newsletter/batching")
def send_newsletter_batching():
task = celery_app.send_newsletter_batching.apply_async()
return JSONResponse({"task_id": task.id})
@app.get("/send-newsletter/locking")
def send_newsletter_locking():
task = celery_app.send_newsletter_locking.apply_async()
return JSONResponse({"task_id": task.id})