-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
23 lines (17 loc) · 670 Bytes
/
Copy pathmain.py
File metadata and controls
23 lines (17 loc) · 670 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from celery import Celery
app = Celery('main',
broker_url="redis://redis/0",
result_backend="redis://redis/0")
@app.task
def custom_header():
return {"request.headers": custom_header.request.headers,
"request.custom_foo": getattr(custom_header.request, "custom_foo", None)}
def main():
app.conf.task_always_eager = True
res = custom_header.apply_async(headers={"custom_foo": "custom_bar"}).get()
print("Eager: %r" % res)
app.conf.task_always_eager = False
res = custom_header.apply_async(headers={"custom_foo": "custom_bar"}).get()
print("Non-Eager: %r" % res)
if __name__ == "__main__":
main()