on microservice way

pull/6/head
Yax 7 years ago
parent 754c37a373
commit cfeabafefb

@ -121,9 +121,6 @@ json_schema = """
"type": "object", "type": "object",
"additionalProperties": false, "additionalProperties": false,
"properties": { "properties": {
"active": {
"type": "boolean"
},
"host": { "host": {
"type": "string" "type": "string"
}, },
@ -135,7 +132,6 @@ json_schema = """
} }
}, },
"required": [ "required": [
"active",
"host", "host",
"pub_port", "pub_port",
"sub_port" "sub_port"

@ -25,10 +25,10 @@ queue = Queue()
proc = None proc = None
env = None env = None
if config.zmq['active']:
context = zmq.Context() context = zmq.Context()
zpub = context.socket(zmq.PUB) zpub = context.socket(zmq.PUB)
zpub.connect('tcp://127.0.0.1:{}'.format(config.zmq['sub_port'])) zpub.connect('tcp://127.0.0.1:{}'.format(config.zmq['sub_port']))
class Processor(Thread): class Processor(Thread):
@ -151,6 +151,9 @@ def reply_comment_email(data):
logger.warn('ignore empty email') logger.warn('ignore empty email')
return return
# accept email: request to delete
send_deletion_order(data)
# safe logic: no answer or unknown answer is a go for publishing # safe logic: no answer or unknown answer is a go for publishing
if message[:2].upper() == 'NO': if message[:2].upper() == 'NO':
# report event # report event
@ -344,7 +347,8 @@ def report(token):
'name': row.name, 'email': row.email}) 'name': row.name, 'email': row.email})
email_body = get_template('report').render(secret=config.security['secret'], email_body = get_template('report').render(secret=config.security['secret'],
root_url=config.http['root_url'], root_url=config.http[
'root_url'],
standbys=standbys, standbys=standbys,
published=published, published=published,
rejected=rejected, rejected=rejected,
@ -373,7 +377,8 @@ def rss(token, onstart=False):
-Comment.published).limit(10): -Comment.published).limit(10):
item_link = "%s://%s%s" % (config.rss['proto'], site.url, row.url) item_link = "%s://%s%s" % (config.rss['proto'], site.url, row.url)
items.append(PyRSS2Gen.RSSItem( items.append(PyRSS2Gen.RSSItem(
title='%s - %s://%s%s' % (config.rss['proto'], row.author_name, site.url, row.url), title='%s - %s://%s%s' % (config.rss['proto'],
row.author_name, site.url, row.url),
link=item_link, link=item_link,
description=md.convert(row.content), description=md.convert(row.content),
guid=PyRSS2Gen.Guid('%s/%d' % (item_link, row.id)), guid=PyRSS2Gen.Guid('%s/%d' % (item_link, row.id)),
@ -391,18 +396,24 @@ def rss(token, onstart=False):
def mail(to_email, subject, message): def mail(to_email, subject, message):
headers = {'Content-Type': 'application/json; charset=utf-8'} zmsg = {
msg = { 'topic': 'email:sendmail',
'to': to_email, 'to': to_email,
'subject': subject, 'subject': subject,
'content': message 'content': message
} }
# do something smart here
# r = requests.post(config.MAIL_URL, data=json.dumps(msg), headers=headers) # TODO test broker failure and find alternative
if r.status_code in (200, 201): zpub.send_string(json.dumps(zmsg, indent=False, sort_keys=False))
logger.debug('Email for %s posted' % to_email) logger.debug('Email for %s posted' % to_email)
else:
logger.warn('Cannot post email for %s' % to_email) #logger.warn('Cannot post email for %s' % to_email)
def send_deletion_order(zmsg):
zmsg['topic'] = 'email:delete'
zpub.send_string(json.dumps(zmsg, indent=False, sort_keys=False))
logger.debug('Email accepted. Deletion request sent for %s' % zmsg)
def get_template(name): def get_template(name):

@ -39,5 +39,6 @@ class Consumer(Thread):
def start(): def start():
logger.info('start zclient')
c = Consumer() c = Consumer()
c.start() c.start()

@ -7,6 +7,7 @@ from clize import clize, run
from jsonschema import validate from jsonschema import validate
from conf import config, schema from conf import config, schema
def load_json(filename): def load_json(filename):
jsondoc = None jsondoc = None
with open(filename, 'rt') as json_file: with open(filename, 'rt') as json_file:
@ -21,7 +22,6 @@ def stacosys_server(config_pathname):
conf = load_json(config_pathname) conf = load_json(config_pathname)
json_schema = json.loads(schema.json_schema) json_schema = json.loads(schema.json_schema)
v = validate(conf, json_schema) v = validate(conf, json_schema)
print('validation: {}'.format(v))
# set configuration # set configuration
config.general = conf['general'] config.general = conf['general']

@ -19,7 +19,6 @@
"file": "comments.xml" "file": "comments.xml"
}, },
"zmq": { "zmq": {
"active": true,
"host": "127.0.0.1", "host": "127.0.0.1",
"pub_port": 7701, "pub_port": 7701,
"sub_port": 7702 "sub_port": 7702

Loading…
Cancel
Save