Commit acb3c4ff authored by Nane Kratzke's avatar Nane Kratzke
Browse files

Aktualisieren prime/rest.py

parent 52c33beb
......@@ -4,12 +4,14 @@ import os
import sys
import json
import logging
import socket
import redis
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
log = logging.getLogger()
redis = redis.StrictRedis(host=os.getenv('REDIS'), port=6379, db=0)
app = Flask(__name__)
hostname = socket.getfqdn()
def lookup(key):
if not os.getenv('REDIS'):
......@@ -40,15 +42,15 @@ def number(number):
n = int(number)
divisor = lookup(n)
if divisor:
return f"{ n } is not a prime number. It can be divided by {divisor} (from cache)"
return f"{ n } is not a prime number. It can be divided by {divisor} (answer from { hostname } via cache)"
for i in range(2, n // 2):
if n % i == 0:
cache(n, i)
return f"{ n } is not a prime number. It can be divided by { i } (processed)"
return f"Yes! random { n } is a prime number."
return f"{ n } is not a prime number. It can be divided by { i } (answer from { hostname }; processed)"
return f"Yes! random { n } is a prime number (answer from { hostname } )."
except Exception as ex:
log.error(f"Exception: { ex }")
abort(500, f"random { n } could not be processed")
abort(500, f"random { n } could not be processed (answer from { hostname }")
log.info(f"Starting prime number checker. My redis server is: {os.getenv('REDIS')}")
app.run(host='0.0.0.0', port=80)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment