-
Notifications
You must be signed in to change notification settings - Fork 0
/
produce.py
29 lines (24 loc) · 822 Bytes
/
produce.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
#!/usr/bin/env python
from celery import Celery
import os
# Define the celery app
app = Celery(
'myApp',
broker=f'''amqp://{os.getenv('BROKER_USER')}:{os.getenv('BROKER_PASS')}@{os.getenv('BROKER_HOST')}:{os.getenv('BROKER_PORT')}''',
backend=f'''rpc://{os.getenv('BACKEND_HOST')}:{os.getenv('BACKEND_PORT')}'''
)
def main():
# Create an empty list to record task instances
tasks = []
# Send your tasks off to the queue
for i in range(10):
tasks.append(
# Send a task to the queue by name (see line 14 in consumer/consume.py)
# Note that task arguments must be a list or tuple
app.send_task('square', (i,))
)
# Retrieve results
for task in tasks:
print(f'Task Result: {task.get()}')
if __name__ == '__main__':
main()