From b96149b00bc7c26ccead4a992af6ee0bae3d6ba2 Mon Sep 17 00:00:00 2001 From: manish-plivo Date: Sun, 6 Dec 2020 12:06:32 +0530 Subject: [PATCH] Revert "change python version to 3.6" --- ci/Dockerfile | 8 +++----- requirements.txt | 12 ++++++------ runner.py | 12 ++++++------ setup.py | 7 ++++--- sharq_server/server.py | 29 +++++++++++++++-------------- src/config/sharq.conf.ctmpl | 16 ++++++++++------ 6 files changed, 44 insertions(+), 40 deletions(-) diff --git a/ci/Dockerfile b/ci/Dockerfile index 1640c33..5f85864 100644 --- a/ci/Dockerfile +++ b/ci/Dockerfile @@ -1,17 +1,15 @@ -FROM python:3.6-slim-buster +FROM python:2.7 ENV CONSUL_TEMPLATE_VERSION 0.19.5 - - RUN mkdir -p /opt/sharq-server WORKDIR /opt/sharq-server COPY . /opt/sharq-server RUN mkdir /etc/supervisord && mkdir /etc/supervisord/conf.d && mkdir /var/log/supervisord && pip install supervisor -RUN apt-get update && apt-get install -y nginx g++ git curl && pip install virtualenv envtpl +RUN apt-get update && apt-get install -y nginx && pip install virtualenv envtpl RUN curl -L https://releases.hashicorp.com/consul-template/${CONSUL_TEMPLATE_VERSION}/consul-template_${CONSUL_TEMPLATE_VERSION}_linux_amd64.tgz | tar -C /usr/sbin -xzf - RUN virtualenv /opt/sharq-server -RUN . /opt/sharq-server/bin/activate && /opt/sharq-server/bin/pip install --no-cache-dir -r /opt/sharq-server/requirements.txt && /opt/sharq-server/bin/python setup.py install -f +RUN . /opt/sharq-server/bin/activate && /opt/sharq-server/bin/pip install --no-cache-dir -r /opt/sharq-server/requirements.txt && /opt/sharq-server/bin/python setup.py install -f && /opt/sharq-server/bin/pip install uwsgi ADD src/config /etc/sharq-server/config ADD src/config/nginx.conf /etc/nginx/nginx.conf diff --git a/requirements.txt b/requirements.txt index 857aeda..0c97928 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,11 +3,11 @@ Jinja2==2.7.2 MarkupSafe==0.23 Werkzeug==0.9.4 argparse==1.2.1 -gevent==20.5.0 -greenlet==0.4.15 +gevent==1.0.1 +greenlet==0.4.2 gunicorn==19.0.0 itsdangerous==0.24 -msgpack==0.5.6 -ujson==2.0.0 -git+https://github.com/plivo/sharq@master -uWSGI==2.0.19.1 +msgpack-python==0.4.2 +ujson==1.33 +wsgiref==0.1.2 +SharQ==0.5.3 diff --git a/runner.py b/runner.py index 0b8ab75..2385d2b 100644 --- a/runner.py +++ b/runner.py @@ -3,7 +3,7 @@ import os import argparse import multiprocessing -import configparser +import ConfigParser import gunicorn.app.base from gunicorn.six import iteritems @@ -49,7 +49,7 @@ def run(): args = parser.parse_args() # read the configuration file and set gunicorn options. - config_parser = configparser.SafeConfigParser() + config_parser = ConfigParser.SafeConfigParser() # get the full path of the config file. sharq_config = os.path.abspath(args.sharq_config) config_parser.read(sharq_config) @@ -59,12 +59,12 @@ def run(): bind = '%s:%s' % (host, port) try: workers = config_parser.get('sharq-server', 'workers') - except configparser.NoOptionError: + except ConfigParser.NoOptionError: workers = number_of_workers() try: accesslog = config_parser.get('sharq-server', 'accesslog') - except configparser.NoOptionError: + except ConfigParser.NoOptionError: accesslog = None options = { @@ -83,7 +83,7 @@ def run(): 'config': gunicorn_config }) - print(""" + print """ ___ _ ___ ___ / __| |_ __ _ _ _ / _ \ / __| ___ _ ___ _____ _ _ \__ \ ' \/ _` | '_| (_) | \__ \/ -_) '_\ V / -_) '_| @@ -92,6 +92,6 @@ def run(): Version: %s Listening on: %s - """ % (__version__, bind)) + """ % (__version__, bind) server = setup_server(sharq_config) SharQServerApplicationRunner(server.app, options).run() diff --git a/setup.py b/setup.py index 36eb131..5f6eb04 100644 --- a/setup.py +++ b/setup.py @@ -18,11 +18,12 @@ 'Jinja2==2.7.2', 'MarkupSafe==0.23', 'Werkzeug==0.9.4', - 'gevent==20.5.0', - 'greenlet==0.4.15', + 'gevent==1.0.1', + 'greenlet==0.4.2', 'itsdangerous==0.24', + 'wsgiref==0.1.2', 'gunicorn==19.0', - 'ujson==2.0.0' + 'ujson==1.33' ], classifiers = [ 'Development Status :: 5 - Production/Stable', diff --git a/sharq_server/server.py b/sharq_server/server.py index 6b892a3..2411636 100644 --- a/sharq_server/server.py +++ b/sharq_server/server.py @@ -2,7 +2,7 @@ # Copyright (c) 2014 Plivo Team. See LICENSE.txt for details. import os import gevent -import configparser +import ConfigParser import ujson as json from flask import Flask, request, jsonify @@ -17,7 +17,7 @@ class SharQServer(object): def __init__(self, config_path): """Load the SharQ config and define the routes.""" # read the configs required by sharq-server. - self.config = configparser.SafeConfigParser() + self.config = ConfigParser.SafeConfigParser() self.config.read(config_path) # pass the config file to configure the SharQ core. self.sq = SharQ(config_path) @@ -76,7 +76,7 @@ def _view_enqueue(self, queue_type, queue_id): } try: request_data = json.loads(request.data) - except Exception as e: + except Exception, e: response['message'] = e.message return jsonify(**response), 400 @@ -87,7 +87,7 @@ def _view_enqueue(self, queue_type, queue_id): try: response = self.sq.enqueue(**request_data) - except Exception as e: + except Exception, e: response['message'] = e.message return jsonify(**response), 400 @@ -106,10 +106,11 @@ def _view_dequeue(self, queue_type): response = self.sq.dequeue(**request_data) if response['status'] == 'failure': return jsonify(**response), 404 - except Exception as e: + except Exception, e: + print e import traceback for line in traceback.format_exc().splitlines(): - print(line) + print line response['message'] = e.message return jsonify(**response), 400 @@ -130,7 +131,7 @@ def _view_finish(self, queue_type, queue_id, job_id): response = self.sq.finish(**request_data) if response['status'] == 'failure': return jsonify(**response), 404 - except Exception as e: + except Exception, e: response['message'] = e.message return jsonify(**response), 400 @@ -144,7 +145,7 @@ def _view_interval(self, queue_type, queue_id): try: request_data = json.loads(request.data) interval = request_data['interval'] - except Exception as e: + except Exception, e: response['message'] = e.message return jsonify(**response), 400 @@ -158,7 +159,7 @@ def _view_interval(self, queue_type, queue_id): response = self.sq.interval(**request_data) if response['status'] == 'failure': return jsonify(**response), 404 - except Exception as e: + except Exception, e: response['message'] = e.message return jsonify(**response), 400 @@ -177,7 +178,7 @@ def _view_metrics(self, queue_type, queue_id): try: response = self.sq.metrics(**request_data) - except Exception as e: + except Exception, e: response['message'] = e.message return jsonify(**response), 400 @@ -193,10 +194,10 @@ def _view_deep_status(self): } return jsonify(**response) except Exception as e: - print(e) + print e import traceback for line in traceback.format_exc().splitlines(): - print(line) + print line raise Exception def _view_clear_queue(self, queue_type, queue_id): @@ -206,7 +207,7 @@ def _view_clear_queue(self, queue_type, queue_id): } try: request_data = json.loads(request.data) - except Exception as e: + except Exception, e: response['message'] = e.message return jsonify(**response), 400 @@ -216,7 +217,7 @@ def _view_clear_queue(self, queue_type, queue_id): }) try: response = self.sq.clear_queue(**request_data) - except Exception as e: + except Exception, e: response['message'] = e.message return jsonify(**response), 400 diff --git a/src/config/sharq.conf.ctmpl b/src/config/sharq.conf.ctmpl index 1014443..a316369 100644 --- a/src/config/sharq.conf.ctmpl +++ b/src/config/sharq.conf.ctmpl @@ -2,21 +2,25 @@ {{$appenv := env "ENVIRONMENT"}} {{$team := env "TEAM"}} {{$sharq_type := env "SHARQ_TYPE"}} - [sharq] -job_expire_interval : 45000 -job_requeue_interval : 1000 -default_job_requeue_limit : -1 +job_expire_interval : 45000 ; in milliseconds +job_requeue_interval : 1000 ; in milliseconds +default_job_requeue_limit : -1 ; retries infinitely [sharq-server] host : 127.0.0.1 port : 8080 -accesslog : /tmp/sharq.log +;; workers : 32 ; optional commenting out to ensure sharq worker is dependent on number of CPUs +accesslog : /tmp/sharq.log ; optional [redis] db : 0 key_prefix : {{ printf "%s/%s/%s/%s/config/redis/key_prefix" $team $appenv $sharq_type $region | key }} -conn_type : tcp_sock +conn_type : tcp_sock ; or tcp_sock +;; unix connection settings +;; unix_socket_path : /var/run/redis/redis.sock +;; tcp connection settings + port : {{ printf "%s/%s/%s/%s/config/redis/port" $team $appenv $sharq_type $region | key | parseInt }} host : {{ printf "%s/%s/%s/%s/config/redis/host" $team $appenv $sharq_type $region | key }} clustered : {{ printf "%s/%s/%s/%s/config/redis/clustered" $team $appenv $sharq_type $region | key }}