Added ping services
This commit is contained in:
parent
5a18d1e978
commit
3c494acd87
|
@ -1,161 +1,161 @@
|
|||
"""
|
||||
This script is executed on start-up after starting up the services, this is intended to check if all the services
|
||||
has started correctly and load all the resources that are required are loaded, after this program is done
|
||||
executing, the bootstrap should start the ping service so that programs know that CoffeeHouse-Utils is ready.
|
||||
"""
|
||||
|
||||
import urllib.parse
|
||||
import requests
|
||||
import base64
|
||||
import time
|
||||
import sys
|
||||
import os
|
||||
|
||||
|
||||
def core_nlp():
|
||||
print("[CORENLP] Warming up")
|
||||
|
||||
current_tries = 0
|
||||
max_tries = 30 # 5 Minutes
|
||||
|
||||
while True:
|
||||
if current_tries > max_tries:
|
||||
print("[CORENLP] ERROR! Too many attempts")
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
r = requests.post("http://127.0.0.1:5604/?properties={\"annotators\": \"tokenize,ssplit,pos,ner,regexner,"
|
||||
"sentiment\"}&pipelineLanguage=en",
|
||||
|
||||
headers={"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8"},
|
||||
data=urllib.parse.quote_plus("The quick brown fox jumped over the lazy dog")
|
||||
)
|
||||
if r.status_code == 200:
|
||||
print("[CORENLP] OK")
|
||||
break
|
||||
else:
|
||||
print("[CORENLP] Failed, Returned status code {0}, '{1}'".format(str(r.status_code), r.text))
|
||||
except:
|
||||
print("[CORENLP] Failed, request not completed")
|
||||
pass
|
||||
|
||||
print("[CORENLP] Waiting 10 seconds")
|
||||
time.sleep(10)
|
||||
current_tries += 1
|
||||
|
||||
print("[CORENLP] Started successfully")
|
||||
|
||||
|
||||
def langdetect():
|
||||
print("[LANGDETECT] Warming up")
|
||||
|
||||
current_tries = 0
|
||||
max_tries = 30 # 5 Minutes
|
||||
while True:
|
||||
if current_tries > max_tries:
|
||||
print("[LANGDETECT] ERROR! Too many attempts")
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
r = requests.post("http://127.0.0.1:5606/", data={"input": "The quick brown fox jumped over the lazy dog"})
|
||||
if r.status_code == 200:
|
||||
print("[LANGDETECT] OK")
|
||||
break
|
||||
else:
|
||||
print("[LANGDETECT] Failed, Returned status code {0}, '{1}'".format(str(r.status_code), r.text))
|
||||
except:
|
||||
print("[LANGDETECT] Failed, request not completed")
|
||||
pass
|
||||
|
||||
print("[LANGDETECT] Waiting 10 seconds")
|
||||
time.sleep(10)
|
||||
current_tries += 1
|
||||
|
||||
print("[LANGDETECT] Started successfully")
|
||||
|
||||
|
||||
def spamdetect():
|
||||
print("[SPAMDETECT] Warming up")
|
||||
|
||||
current_tries = 0
|
||||
max_tries = 30 # 5 Minutes
|
||||
while True:
|
||||
if current_tries > max_tries:
|
||||
print("[SPAMDETECT] ERROR! Too many attempts")
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
r = requests.post("http://127.0.0.1:5601/", data={"input": "The quick brown fox jumped over the lazy dog"})
|
||||
if r.status_code == 200:
|
||||
print("[SPAMDETECT] OK")
|
||||
break
|
||||
else:
|
||||
print("[SPAMDETECT] Failed, Returned status code {0}, '{1}'".format(str(r.status_code), r.text))
|
||||
except:
|
||||
print("[SPAMDETECT] Failed, request not completed")
|
||||
pass
|
||||
|
||||
print("[SPAMDETECT] Waiting 10 seconds")
|
||||
time.sleep(10)
|
||||
current_tries += 1
|
||||
|
||||
print("[SPAMDETECT] Started successfully")
|
||||
|
||||
|
||||
def nsfw():
|
||||
print("[NSFW] Warming up")
|
||||
|
||||
current_tries = 0
|
||||
max_tries = 30 # 5 Minutes
|
||||
|
||||
with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), "red.jpg"), "rb") as img_file:
|
||||
image_data = base64.b64encode(img_file.read()).decode('utf-8')
|
||||
|
||||
while True:
|
||||
if current_tries > max_tries:
|
||||
print("[NSFW] ERROR! Too many attempts")
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
r = requests.post("http://127.0.0.1:5602/", data={
|
||||
"input": image_data,
|
||||
"type": "jpg"
|
||||
})
|
||||
if r.status_code == 200:
|
||||
print("[NSFW] OK")
|
||||
break
|
||||
else:
|
||||
print("[NSFW] Failed, Returned status code {0}, '{1}'".format(str(r.status_code), r.text))
|
||||
except:
|
||||
print("[NSFW] Failed, request not completed")
|
||||
pass
|
||||
|
||||
print("[NSFW] Waiting 10 seconds")
|
||||
time.sleep(10)
|
||||
current_tries += 1
|
||||
|
||||
print("[NSFW] Started successfully")
|
||||
|
||||
|
||||
print(" ( ) ( ) )")
|
||||
print(" ) ( ) ( (")
|
||||
print(" ( ) ( ) )")
|
||||
print(" _____________")
|
||||
print(" <_____________> ___")
|
||||
print(" | |/ _ \\")
|
||||
print(" | | | |")
|
||||
print(" | |_| |")
|
||||
print(" ___| |\___/")
|
||||
print("/ \___________/ \\")
|
||||
print("\_____________________/")
|
||||
print()
|
||||
print("CoffeeHouse-Utils Warmup")
|
||||
|
||||
core_nlp()
|
||||
spamdetect()
|
||||
langdetect()
|
||||
nsfw()
|
||||
|
||||
print("OK, CoffeeHouse-Utils seems to be running fine.")
|
||||
print("Exiting with code 0, the ping service should start in the next step.")
|
||||
sys.exit(0)
|
||||
"""
|
||||
This script is executed on start-up after starting up the services, this is intended to check if all the services
|
||||
has started correctly and load all the resources that are required are loaded, after this program is done
|
||||
executing, the bootstrap should start the ping service so that programs know that CoffeeHouse-Utils is ready.
|
||||
"""
|
||||
|
||||
import urllib.parse
|
||||
import requests
|
||||
import base64
|
||||
import time
|
||||
import sys
|
||||
import os
|
||||
|
||||
|
||||
def core_nlp():
|
||||
print("[CORENLP] Warming up")
|
||||
|
||||
current_tries = 0
|
||||
max_tries = 30 # 5 Minutes
|
||||
|
||||
while True:
|
||||
if current_tries > max_tries:
|
||||
print("[CORENLP] ERROR! Too many attempts")
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
r = requests.post("http://127.0.0.1:5604/?properties={\"annotators\": \"tokenize,ssplit,pos,ner,regexner,"
|
||||
"sentiment\"}&pipelineLanguage=en",
|
||||
|
||||
headers={"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8"},
|
||||
data=urllib.parse.quote_plus("The quick brown fox jumped over the lazy dog")
|
||||
)
|
||||
if r.status_code == 200:
|
||||
print("[CORENLP] OK")
|
||||
break
|
||||
else:
|
||||
print("[CORENLP] Failed, Returned status code {0}, '{1}'".format(str(r.status_code), r.text))
|
||||
except:
|
||||
print("[CORENLP] Failed, request not completed")
|
||||
pass
|
||||
|
||||
print("[CORENLP] Waiting 10 seconds")
|
||||
time.sleep(10)
|
||||
current_tries += 1
|
||||
|
||||
print("[CORENLP] Started successfully")
|
||||
|
||||
|
||||
def langdetect():
|
||||
print("[LANGDETECT] Warming up")
|
||||
|
||||
current_tries = 0
|
||||
max_tries = 30 # 5 Minutes
|
||||
while True:
|
||||
if current_tries > max_tries:
|
||||
print("[LANGDETECT] ERROR! Too many attempts")
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
r = requests.post("http://127.0.0.1:5606/", data={"input": "The quick brown fox jumped over the lazy dog"})
|
||||
if r.status_code == 200:
|
||||
print("[LANGDETECT] OK")
|
||||
break
|
||||
else:
|
||||
print("[LANGDETECT] Failed, Returned status code {0}, '{1}'".format(str(r.status_code), r.text))
|
||||
except:
|
||||
print("[LANGDETECT] Failed, request not completed")
|
||||
pass
|
||||
|
||||
print("[LANGDETECT] Waiting 10 seconds")
|
||||
time.sleep(10)
|
||||
current_tries += 1
|
||||
|
||||
print("[LANGDETECT] Started successfully")
|
||||
|
||||
|
||||
def spamdetect():
|
||||
print("[SPAMDETECT] Warming up")
|
||||
|
||||
current_tries = 0
|
||||
max_tries = 30 # 5 Minutes
|
||||
while True:
|
||||
if current_tries > max_tries:
|
||||
print("[SPAMDETECT] ERROR! Too many attempts")
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
r = requests.post("http://127.0.0.1:5601/", data={"input": "The quick brown fox jumped over the lazy dog"})
|
||||
if r.status_code == 200:
|
||||
print("[SPAMDETECT] OK")
|
||||
break
|
||||
else:
|
||||
print("[SPAMDETECT] Failed, Returned status code {0}, '{1}'".format(str(r.status_code), r.text))
|
||||
except:
|
||||
print("[SPAMDETECT] Failed, request not completed")
|
||||
pass
|
||||
|
||||
print("[SPAMDETECT] Waiting 10 seconds")
|
||||
time.sleep(10)
|
||||
current_tries += 1
|
||||
|
||||
print("[SPAMDETECT] Started successfully")
|
||||
|
||||
|
||||
def nsfw():
|
||||
print("[NSFW] Warming up")
|
||||
|
||||
current_tries = 0
|
||||
max_tries = 30 # 5 Minutes
|
||||
|
||||
with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), "red.jpg"), "rb") as img_file:
|
||||
image_data = base64.b64encode(img_file.read()).decode('utf-8')
|
||||
|
||||
while True:
|
||||
if current_tries > max_tries:
|
||||
print("[NSFW] ERROR! Too many attempts")
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
r = requests.post("http://127.0.0.1:5602/", data={
|
||||
"input": image_data,
|
||||
"type": "jpg"
|
||||
})
|
||||
if r.status_code == 200:
|
||||
print("[NSFW] OK")
|
||||
break
|
||||
else:
|
||||
print("[NSFW] Failed, Returned status code {0}, '{1}'".format(str(r.status_code), r.text))
|
||||
except:
|
||||
print("[NSFW] Failed, request not completed")
|
||||
pass
|
||||
|
||||
print("[NSFW] Waiting 10 seconds")
|
||||
time.sleep(10)
|
||||
current_tries += 1
|
||||
|
||||
print("[NSFW] Started successfully")
|
||||
|
||||
|
||||
print(" ( ) ( ) )")
|
||||
print(" ) ( ) ( (")
|
||||
print(" ( ) ( ) )")
|
||||
print(" _____________")
|
||||
print(" <_____________> ___")
|
||||
print(" | |/ _ \\")
|
||||
print(" | | | |")
|
||||
print(" | |_| |")
|
||||
print(" ___| |\___/")
|
||||
print("/ \___________/ \\")
|
||||
print("\_____________________/")
|
||||
print()
|
||||
print("CoffeeHouse-Utils Warmup")
|
||||
|
||||
core_nlp()
|
||||
spamdetect()
|
||||
langdetect()
|
||||
nsfw()
|
||||
|
||||
print("OK, CoffeeHouse-Utils seems to be running fine.")
|
||||
print("Exiting with code 0, the ping service should start in the next step.")
|
||||
sys.exit(0)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from . import server
|
||||
from .server import *
|
||||
|
||||
from . import server
|
||||
from .server import *
|
||||
|
||||
__all__ = ["Server"]
|
|
@ -1,50 +1,50 @@
|
|||
import sys
|
||||
|
||||
from coffeehouse_ping import Server
|
||||
|
||||
|
||||
def _real_main(argv=None):
|
||||
"""
|
||||
The main command-line processor
|
||||
|
||||
:param argv:
|
||||
:return:
|
||||
"""
|
||||
if argv[1] == '--help':
|
||||
_help_menu(argv)
|
||||
if argv[1] == '--start-server':
|
||||
_start_server(argv)
|
||||
|
||||
|
||||
def _start_server(argv=None):
|
||||
"""
|
||||
Starts the server
|
||||
|
||||
:param argv:
|
||||
:return:
|
||||
"""
|
||||
server = Server()
|
||||
server.start()
|
||||
|
||||
|
||||
def _help_menu(argv=None):
|
||||
"""
|
||||
Displays the help menu and commandline usage
|
||||
|
||||
:param argv:
|
||||
:return:
|
||||
"""
|
||||
print(
|
||||
"CoffeeHouse Ping CLI\n\n"
|
||||
" --help\n"
|
||||
" --start-server\n"
|
||||
)
|
||||
sys.exit()
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
try:
|
||||
_real_main(sys.argv)
|
||||
except KeyboardInterrupt:
|
||||
print('\nInterrupted by user')
|
||||
import sys
|
||||
|
||||
from coffeehouse_ping import Server
|
||||
|
||||
|
||||
def _real_main(argv=None):
|
||||
"""
|
||||
The main command-line processor
|
||||
|
||||
:param argv:
|
||||
:return:
|
||||
"""
|
||||
if argv[1] == '--help':
|
||||
_help_menu(argv)
|
||||
if argv[1] == '--start-server':
|
||||
_start_server(argv)
|
||||
|
||||
|
||||
def _start_server(argv=None):
|
||||
"""
|
||||
Starts the server
|
||||
|
||||
:param argv:
|
||||
:return:
|
||||
"""
|
||||
server = Server()
|
||||
server.start()
|
||||
|
||||
|
||||
def _help_menu(argv=None):
|
||||
"""
|
||||
Displays the help menu and commandline usage
|
||||
|
||||
:param argv:
|
||||
:return:
|
||||
"""
|
||||
print(
|
||||
"CoffeeHouse Ping CLI\n\n"
|
||||
" --help\n"
|
||||
" --start-server\n"
|
||||
)
|
||||
sys.exit()
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
try:
|
||||
_real_main(sys.argv)
|
||||
except KeyboardInterrupt:
|
||||
print('\nInterrupted by user')
|
||||
|
|
|
@ -1,44 +1,44 @@
|
|||
from hyper_internal_service import web
|
||||
|
||||
__all__ = ['Server']
|
||||
|
||||
|
||||
class Server(object):
|
||||
|
||||
def __init__(self, port=5600):
|
||||
"""
|
||||
Public Constructor
|
||||
:param port:
|
||||
"""
|
||||
self.port = port
|
||||
self.web_application = web.Application()
|
||||
self.web_application.add_routes(
|
||||
[web.post('/', self.ping)]
|
||||
)
|
||||
|
||||
async def ping(self, request):
|
||||
"""
|
||||
Handles the predict request "/", usage:
|
||||
POST:: "input": str
|
||||
:param request:
|
||||
:return:
|
||||
"""
|
||||
post_data = await request.post()
|
||||
return web.json_response({"status": True})
|
||||
|
||||
def start(self):
|
||||
"""
|
||||
Starts the web application
|
||||
:return:
|
||||
"""
|
||||
web.run_app(app=self.web_application, port=self.port)
|
||||
return True
|
||||
|
||||
def stop(self):
|
||||
"""
|
||||
Stops the web application
|
||||
:return:
|
||||
"""
|
||||
self.web_application.shutdown()
|
||||
self.web_application.cleanup()
|
||||
from hyper_internal_service import web
|
||||
|
||||
__all__ = ['Server']
|
||||
|
||||
|
||||
class Server(object):
|
||||
|
||||
def __init__(self, port=5600):
|
||||
"""
|
||||
Public Constructor
|
||||
:param port:
|
||||
"""
|
||||
self.port = port
|
||||
self.web_application = web.Application()
|
||||
self.web_application.add_routes(
|
||||
[web.post('/', self.ping)]
|
||||
)
|
||||
|
||||
async def ping(self, request):
|
||||
"""
|
||||
Handles the predict request "/", usage:
|
||||
POST:: "input": str
|
||||
:param request:
|
||||
:return:
|
||||
"""
|
||||
post_data = await request.post()
|
||||
return web.json_response({"status": True})
|
||||
|
||||
def start(self):
|
||||
"""
|
||||
Starts the web application
|
||||
:return:
|
||||
"""
|
||||
web.run_app(app=self.web_application, port=self.port)
|
||||
return True
|
||||
|
||||
def stop(self):
|
||||
"""
|
||||
Stops the web application
|
||||
:return:
|
||||
"""
|
||||
self.web_application.shutdown()
|
||||
self.web_application.cleanup()
|
||||
return True
|
|
@ -1,16 +1,16 @@
|
|||
from setuptools import setup, find_packages
|
||||
from setuptools.command.install import install
|
||||
|
||||
|
||||
setup(
|
||||
name='coffeehouse_ping',
|
||||
version='1.0.0',
|
||||
description='Provides an endpoint for programs to ping for CoffeeHouse-Utils',
|
||||
url='https://github.com/Intellivoid/CoffeeHousePy',
|
||||
author='Zi Xing Narrakas',
|
||||
author_email='netkas@intellivoid.info',
|
||||
classifiers=[
|
||||
'Development Status :: 3 - Internal/Alpha'
|
||||
],
|
||||
packages=find_packages()
|
||||
)
|
||||
from setuptools import setup, find_packages
|
||||
from setuptools.command.install import install
|
||||
|
||||
|
||||
setup(
|
||||
name='coffeehouse_ping',
|
||||
version='1.0.0',
|
||||
description='Provides an endpoint for programs to ping for CoffeeHouse-Utils',
|
||||
url='https://github.com/Intellivoid/CoffeeHousePy',
|
||||
author='Zi Xing Narrakas',
|
||||
author_email='netkas@intellivoid.info',
|
||||
classifiers=[
|
||||
'Development Status :: 3 - Internal/Alpha'
|
||||
],
|
||||
packages=find_packages()
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue