-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathworker.py
More file actions
36 lines (22 loc) · 781 Bytes
/
worker.py
File metadata and controls
36 lines (22 loc) · 781 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
34
35
36
import logging
logging.basicConfig(level=logging.INFO)
from faktory import Worker
def add_numbers(x, y):
calc = x + y
print(f"add: {x} + {y} = {calc}")
return calc
def subtract_numbers(x, y):
calc = x - y
print(f"subtract: {x} - {y} = {calc}")
return calc
def multiply_numbers(x, y):
calc = x * y
print(f"multiply: {x} * {y} = {calc}")
return calc
if __name__ == "__main__":
w = Worker(faktory="tcp://localhost:7419", queues=["default"], concurrency=1)
w.register("add", add_numbers)
w.register("subtract", subtract_numbers)
w.register("multiply", multiply_numbers)
w.run() # runs until control-c or worker shutdown from Faktory web UI
# check examples/producer.py for how to submit tasks to be run by faktory