-
-
Save ttstarck/a067eda1aa2f4c211c605351f175c537 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
from datetime import datetime | |
logging.basicConfig(level=logging.DEBUG) | |
from faktory import Worker | |
def add_numbers(x, y): | |
calc = x + y | |
current_time = datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S.%f') | |
print(f"{current_time} - add: {x} + {y} = {calc}") | |
return calc | |
def subtract_numbers(x, y): | |
calc = x - y | |
current_time = datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S.%f') | |
print(f"{current_time} subtract: {x} - {y} = {calc}") | |
return calc | |
def multiply_numbers(x, y): | |
calc = x * y | |
current_time = datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S.%f') | |
print(f"{current_time} 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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment