Skip to content

Commit

Permalink
Merge pull request #30 from plivo/revert-25-py2to3
Browse files Browse the repository at this point in the history
Revert "change python version to 3.6"
  • Loading branch information
manish-plivo authored Dec 6, 2020
2 parents e10b2ae + b96149b commit 2a84f72
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 40 deletions.
8 changes: 3 additions & 5 deletions ci/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
12 changes: 6 additions & 6 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 6 additions & 6 deletions runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os
import argparse
import multiprocessing
import configparser
import ConfigParser

import gunicorn.app.base
from gunicorn.six import iteritems
Expand Down Expand Up @@ -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)
Expand All @@ -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 = {
Expand All @@ -83,7 +83,7 @@ def run():
'config': gunicorn_config
})

print("""
print """
___ _ ___ ___
/ __| |_ __ _ _ _ / _ \ / __| ___ _ ___ _____ _ _
\__ \ ' \/ _` | '_| (_) | \__ \/ -_) '_\ V / -_) '_|
Expand All @@ -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()
7 changes: 4 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
29 changes: 15 additions & 14 deletions sharq_server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand Down Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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):
Expand All @@ -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

Expand All @@ -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

Expand Down
16 changes: 10 additions & 6 deletions src/config/sharq.conf.ctmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

0 comments on commit 2a84f72

Please sign in to comment.