on microservice way
This commit is contained in:
parent
8ebed3cda6
commit
cedac41b10
5 changed files with 31 additions and 24 deletions
|
@ -121,9 +121,6 @@ json_schema = """
|
|||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"active": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"host": {
|
||||
"type": "string"
|
||||
},
|
||||
|
@ -135,7 +132,6 @@ json_schema = """
|
|||
}
|
||||
},
|
||||
"required": [
|
||||
"active",
|
||||
"host",
|
||||
"pub_port",
|
||||
"sub_port"
|
||||
|
|
|
@ -25,10 +25,10 @@ queue = Queue()
|
|||
proc = None
|
||||
env = None
|
||||
|
||||
if config.zmq['active']:
|
||||
context = zmq.Context()
|
||||
zpub = context.socket(zmq.PUB)
|
||||
zpub.connect('tcp://127.0.0.1:{}'.format(config.zmq['sub_port']))
|
||||
|
||||
context = zmq.Context()
|
||||
zpub = context.socket(zmq.PUB)
|
||||
zpub.connect('tcp://127.0.0.1:{}'.format(config.zmq['sub_port']))
|
||||
|
||||
|
||||
class Processor(Thread):
|
||||
|
@ -78,7 +78,7 @@ def new_comment(data):
|
|||
if config.security['private']:
|
||||
author_gravatar = author_email
|
||||
author_email = ''
|
||||
else:
|
||||
else:
|
||||
author_gravatar = md5(author_email.lower())
|
||||
|
||||
# create a new comment row
|
||||
|
@ -151,6 +151,9 @@ def reply_comment_email(data):
|
|||
logger.warn('ignore empty email')
|
||||
return
|
||||
|
||||
# accept email: request to delete
|
||||
send_deletion_order(data)
|
||||
|
||||
# safe logic: no answer or unknown answer is a go for publishing
|
||||
if message[:2].upper() == 'NO':
|
||||
# report event
|
||||
|
@ -344,7 +347,8 @@ def report(token):
|
|||
'name': row.name, 'email': row.email})
|
||||
|
||||
email_body = get_template('report').render(secret=config.security['secret'],
|
||||
root_url=config.http['root_url'],
|
||||
root_url=config.http[
|
||||
'root_url'],
|
||||
standbys=standbys,
|
||||
published=published,
|
||||
rejected=rejected,
|
||||
|
@ -373,7 +377,8 @@ def rss(token, onstart=False):
|
|||
-Comment.published).limit(10):
|
||||
item_link = "%s://%s%s" % (config.rss['proto'], site.url, row.url)
|
||||
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,
|
||||
description=md.convert(row.content),
|
||||
guid=PyRSS2Gen.Guid('%s/%d' % (item_link, row.id)),
|
||||
|
@ -391,18 +396,24 @@ def rss(token, onstart=False):
|
|||
|
||||
def mail(to_email, subject, message):
|
||||
|
||||
headers = {'Content-Type': 'application/json; charset=utf-8'}
|
||||
msg = {
|
||||
zmsg = {
|
||||
'topic': 'email:sendmail',
|
||||
'to': to_email,
|
||||
'subject': subject,
|
||||
'content': message
|
||||
}
|
||||
# do something smart here
|
||||
# r = requests.post(config.MAIL_URL, data=json.dumps(msg), headers=headers)
|
||||
if r.status_code in (200, 201):
|
||||
logger.debug('Email for %s posted' % to_email)
|
||||
else:
|
||||
logger.warn('Cannot post email for %s' % to_email)
|
||||
|
||||
# TODO test broker failure and find alternative
|
||||
zpub.send_string(json.dumps(zmsg, indent=False, sort_keys=False))
|
||||
logger.debug('Email for %s posted' % 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):
|
||||
|
|
|
@ -39,5 +39,6 @@ class Consumer(Thread):
|
|||
|
||||
|
||||
def start():
|
||||
logger.info('start zclient')
|
||||
c = Consumer()
|
||||
c.start()
|
||||
|
|
|
@ -7,6 +7,7 @@ from clize import clize, run
|
|||
from jsonschema import validate
|
||||
from conf import config, schema
|
||||
|
||||
|
||||
def load_json(filename):
|
||||
jsondoc = None
|
||||
with open(filename, 'rt') as json_file:
|
||||
|
@ -19,10 +20,9 @@ def stacosys_server(config_pathname):
|
|||
|
||||
# load and validate startup config
|
||||
conf = load_json(config_pathname)
|
||||
json_schema = json.loads(schema.json_schema)
|
||||
json_schema = json.loads(schema.json_schema)
|
||||
v = validate(conf, json_schema)
|
||||
print('validation: {}'.format(v))
|
||||
|
||||
|
||||
# set configuration
|
||||
config.general = conf['general']
|
||||
config.http = conf['http']
|
||||
|
@ -34,4 +34,4 @@ def stacosys_server(config_pathname):
|
|||
from core import app
|
||||
|
||||
if __name__ == '__main__':
|
||||
run(stacosys_server)
|
||||
run(stacosys_server)
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
"file": "comments.xml"
|
||||
},
|
||||
"zmq": {
|
||||
"active": true,
|
||||
"host": "127.0.0.1",
|
||||
"pub_port": 7701,
|
||||
"sub_port": 7702
|
||||
|
|
Loading…
Add table
Reference in a new issue