From 05d363ca67322070453f1d63aa6ee75787ec9f24 Mon Sep 17 00:00:00 2001
From: Sebastian Rieger <sebastian.rieger@informatik.hs-fulda.de>
Date: Mon, 18 Mar 2024 14:38:45 +0100
Subject: [PATCH] removed anyjson, refactoring based on pylint recommendations

---
 faafo/faafo/api/service.py    | 16 ++++++++--------
 faafo/faafo/worker/service.py | 13 ++++++++-----
 faafo/requirements.txt        |  2 +-
 3 files changed, 17 insertions(+), 14 deletions(-)

diff --git a/faafo/faafo/api/service.py b/faafo/faafo/api/service.py
index 00f2e98..8843999 100644
--- a/faafo/faafo/api/service.py
+++ b/faafo/faafo/api/service.py
@@ -112,7 +112,7 @@ connection = Connection(CONF.transport_url)
 def index(page=1):
     hostname = socket.gethostname()
     fractals = Fractal.query.filter(
-        (Fractal.checksum != None) & (Fractal.size != None)).paginate(
+        (Fractal.checksum is not None) & (Fractal.size is not None)).paginate(
             page=page, per_page=5)
     return flask.render_template('index.html', fractals=fractals, hostname=hostname)
 
@@ -137,7 +137,7 @@ def get_fractal(fractalid):
 
 
 def generate_fractal(**kwargs):
-    print("Postprocessor called!" + str(kwargs))
+    LOG.debug("Postprocessor called!" + str(kwargs))
     with producers[connection].acquire(block=True) as producer:
         producer.publish(kwargs['result'],
                          serializer='json',
@@ -145,13 +145,14 @@ def generate_fractal(**kwargs):
                          declare=[queues.task_exchange],
                          routing_key='normal')
 
+
 def convert_image_to_binary(**kwargs):
-    print("Preprocessor call: " + str(kwargs))
+    LOG.debug("Preprocessor call: " + str(kwargs))
     if 'image' in kwargs['data']['data']['attributes']:
-        print("Converting image to binary...")
-        kwargs['data']['data']['attributes']['image'] = str(kwargs['data']['data']['attributes']['image']).encode("ascii")
-    #print("Preprocessor called!" + str(kwargs))
-    #return kwargs
+        LOG.debug("Converting image to binary...")
+        kwargs['data']['data']['attributes']['image'] = \
+            str(kwargs['data']['data']['attributes']['image']).encode("ascii")
+
 
 def main():
     print("Starting API server - new...")
@@ -163,4 +164,3 @@ def main():
                            url_prefix='/v1',
                            allow_client_generated_ids=True)
     app.run(host=CONF.listen_address, port=CONF.bind_port, debug=True)
-
diff --git a/faafo/faafo/worker/service.py b/faafo/faafo/worker/service.py
index 0ab6ce6..edd4784 100644
--- a/faafo/faafo/worker/service.py
+++ b/faafo/faafo/worker/service.py
@@ -19,12 +19,13 @@ import copy
 import hashlib
 import json
 import os
-from PIL import Image
 import random
 import socket
 import tempfile
 import time
 
+from PIL import Image
+
 from kombu.mixins import ConsumerMixin
 from oslo_config import cfg
 from oslo_log import log
@@ -152,11 +153,13 @@ class Worker(ConsumerMixin):
         }
 
         headers = {'Content-Type': 'application/vnd.api+json',
-                    'Accept': 'application/vnd.api+json'}
-        
+                   'Accept': 'application/vnd.api+json'}
+
         resp = requests.patch("%s/v1/fractal/%s" %
-                     (CONF.endpoint_url, str(task['uuid'])),
-                     json.dumps(result), headers=headers)
+                              (CONF.endpoint_url, str(task['uuid'])),
+                              json.dumps(result), 
+                              headers=headers,
+                              timeout=30)
         LOG.debug("Result: %s" % resp.text)
 
         message.ack()
diff --git a/faafo/requirements.txt b/faafo/requirements.txt
index 2f9abf2..fd17007 100644
--- a/faafo/requirements.txt
+++ b/faafo/requirements.txt
@@ -4,7 +4,7 @@ pytz
 positional
 iso8601
 #anyjson>=0.3.3
-anyjson
+#anyjson
 #eventlet>=0.17.4
 eventlet
 #PyMySQL>=0.6.2,<0.7  # 0.7 design change breaks faafo, MIT License
-- 
GitLab