disable shutdown command for demo
This commit is contained in:
parent
108193c38c
commit
01ea656fce
2 changed files with 28 additions and 18 deletions
|
|
@ -28,10 +28,9 @@ async def api(request):
|
|||
command = postdata.get('command').split(' ')
|
||||
if command[0] == "status":
|
||||
try:
|
||||
count_tables = "SELECT COUNT(*) FROM CompanyC.INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE'"
|
||||
await request.config_dict['cur'].execute(count_tables)
|
||||
result = await request.config_dict['cur'].fetchone()
|
||||
tables = result[0]
|
||||
count_tables = "SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE'"
|
||||
results = await request.config_dict['query'](count_tables)
|
||||
tables = results[0][0]
|
||||
db_status = 'OK'
|
||||
except Exception as e:
|
||||
tables = 0
|
||||
|
|
@ -43,28 +42,38 @@ async def api(request):
|
|||
ram_stats = psutil.virtual_memory()
|
||||
ram_total = ram_stats[0]
|
||||
ram_used = ram_stats[3]
|
||||
|
||||
data = f"""\
|
||||
Web server status: {request.config_dict['stats']['status']}, started {request.config_dict['start']:%Y-%m-%d %H:%M:%S}.
|
||||
Database at {request.config_dict['config']['database']['host']}: {db_status}, access to {tables:,} tables.
|
||||
Load on {core_count} cores, {thread_count} threads: {cpu_load}%. Using {ram_used/1024**3:.1f} GiB of {ram_total/1024**3:.1f} GiB memory."""
|
||||
return web.json_response({'status': 'ok', 'data': data, 'timestamp': timestamp})
|
||||
|
||||
elif command[0] == "shutdown":
|
||||
#request.config_dict['stats']['status'] = 'Shutting down'
|
||||
delay = 5 if len(command) == 1 else int(command[1])
|
||||
delay = max(delay, 0)
|
||||
#asyncio.create_task(shutdown(request.config_dict['runner'], request.config_dict['waiter'], delay))
|
||||
return web.json_response({'status': 'ok', 'data': f'This would shut down the app in {delay} seconds, but the feature is disabled for this demo.', 'timestamp': timestamp})
|
||||
|
||||
elif command[0] == "fortune":
|
||||
magic_8_ball = [
|
||||
"It is certain", "It is decidedly so", "Without a doubt", "Yes definitely", "You may rely on it",
|
||||
"As I see it, yes", "Most likely", "Outlook good", "Yes", "Signs point to yes",
|
||||
"Reply hazy, try again", "Ask again later", "Better not tell you now", "Cannot predict now", "Concentrate and ask again",
|
||||
"Don't count on it", "My reply is no", "My sources say no", "Outlook not so good", "Very doubtful"
|
||||
]
|
||||
return web.json_response({'status': 'ok', 'data': f'Your magic 8-ball prediction: {random.choice(magic_8_ball)}', 'timestamp': timestamp})
|
||||
|
||||
data = f"""\
|
||||
Web server status: {request.config_dict['stats']['status']}, started {request.config_dict['start']:%Y-%m-%d %H:%M:%S}.
|
||||
Database at {request.config_dict['config']['database']['host']}: {db_status}, access to {tables:,} tables.
|
||||
Load on {core_count} cores, {thread_count} threads: {cpu_load}%. Using {ram_used/1024**3:.1f} GiB of {ram_total/1024**3:.1f} GiB memory.
|
||||
Your magic 8-ball prediction: {random.choice(magic_8_ball)}."""
|
||||
return web.json_response({'status': 'ok', 'data': data, 'timestamp': timestamp})
|
||||
|
||||
elif command[0] == "shutdown":
|
||||
request.config_dict['stats']['status'] = 'Shutting down'
|
||||
delay = 5 if len(command) == 1 else int(command[1])
|
||||
asyncio.create_task(shutdown(request.config_dict['runner'], request.config_dict['waiter'], delay))
|
||||
return web.json_response({'status': 'ok', 'data': f'Shutting down in {delay} seconds...', 'timestamp': timestamp})
|
||||
elif command[0] == "help":
|
||||
message = """\
|
||||
status - Prints an overview of system operation and resource usage
|
||||
shutdown [delay] - Shuts down the application after a timeout in seconds (default 5, disabled for this demo)
|
||||
help - Prints this message"""
|
||||
return web.json_response({'status': 'ok', 'data': message, 'timestamp': timestamp})
|
||||
|
||||
else:
|
||||
return web.json_response({'status': 'error', 'data': f'Unrecognized command "{command[0]}"', 'timestamp': timestamp})
|
||||
return web.json_response({'status': 'error', 'data': f'Unrecognized command "{command[0]}", try "help".', 'timestamp': timestamp})
|
||||
|
||||
async def shutdown(runner, waiter, delay=0):
|
||||
await asyncio.sleep(delay)
|
||||
|
|
|
|||
|
|
@ -39,7 +39,8 @@
|
|||
<select class="form-select mb-3" id="commandlist">
|
||||
<option value="" disabled selected>Commands</option>
|
||||
<option value="status">Status</option>
|
||||
<option value="shutdown">Shut down</option>
|
||||
<option value="shutdown">Shut down (disabled for this demo)</option>
|
||||
<option value="fortune">Fortune</option>
|
||||
</select>
|
||||
<div id="output" class="w-100 border overflow-y-auto p-2 mb-3"></div>
|
||||
<form method="post" action="/reporter/admin/api" id="commandform" class="mb-3" autocomplete="off">
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue