Removed DeVries. Added process monitoring to collection process so it will restart if it dies. Seems to be a 2h limit on API, so reporting has been failing at the end of long races.
This commit is contained in:
parent
fb7387fc47
commit
090230f11a
1
create_queue_db.py
Normal file → Executable file
1
create_queue_db.py
Normal file → Executable file
@ -1,3 +1,4 @@
|
||||
#!/usr/bin/python3
|
||||
import sqlite3
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
53
robottas.py
53
robottas.py
@ -1,9 +1,12 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
import asyncio
|
||||
from asyncio.subprocess import PIPE, STDOUT
|
||||
import collections.abc
|
||||
import json
|
||||
import os
|
||||
import sqlite3
|
||||
from subprocess import Popen
|
||||
import time
|
||||
import discord
|
||||
|
||||
@ -497,6 +500,7 @@ class Robottas(commands.Bot):
|
||||
async def _report(self, ctx):
|
||||
self.is_reporting = True
|
||||
self.channel = ctx.channel
|
||||
await self.start_collect()
|
||||
|
||||
while self.is_reporting:
|
||||
# Do processing
|
||||
@ -515,17 +519,46 @@ class Robottas(commands.Bot):
|
||||
# process any messages in the delay queue
|
||||
await self.process_delay_messages()
|
||||
|
||||
#If collecting, make sure the collection process is running
|
||||
if self.is_collecting:
|
||||
if self.collector_proc == None or \
|
||||
self.collector_proc.poll() != None:
|
||||
await self.start_collect()
|
||||
|
||||
|
||||
def get_token(self, token_file):
|
||||
with open(token_file) as tok:
|
||||
return tok.readline().strip()
|
||||
|
||||
|
||||
async def start_collect(self):
|
||||
self.is_collecting = True
|
||||
dir_path = os.path.dirname(os.path.realpath(__file__))
|
||||
command_txt = os.path.join(dir_path, self.collector_command)
|
||||
command_txt += self.collector_params
|
||||
print(f"command_txt: {command_txt}")
|
||||
self.collector_proc = Popen(command_txt.split())
|
||||
|
||||
|
||||
async def stop_collect(self):
|
||||
self.is_collecting = False
|
||||
try:
|
||||
if self.collector_proc != None:
|
||||
self.collector_proc.kill()
|
||||
except:
|
||||
print("Tried to kill collection process")
|
||||
|
||||
|
||||
def __init__(self):
|
||||
# Set debug or not
|
||||
self.debug = True
|
||||
|
||||
# Discord authentication token
|
||||
self.token = self.get_token("token.txt")
|
||||
self.collector_command = "robottas_collector.py"
|
||||
self.collector_params = " save dummy.txt"
|
||||
self.collector_proc = None
|
||||
self.is_collecting = False
|
||||
|
||||
# Preface messages with the following
|
||||
self.report_preamble = ':robot::peach: Alert!'
|
||||
@ -580,7 +613,6 @@ class Robottas(commands.Bot):
|
||||
'20': '<:MAG:1067883814992486510>',
|
||||
'23': '<:ALB:1067874026871074887>',
|
||||
'2': '<:SAR:1067890949197414410>',
|
||||
'21': '<:DEV:1067891622727131248>'
|
||||
}
|
||||
|
||||
# Holds dictionary for driver 3 letter code to icon
|
||||
@ -606,7 +638,6 @@ class Robottas(commands.Bot):
|
||||
'MAG': '<:MAG:1067883814992486510>',
|
||||
'ALB': '<:ALB:1067874026871074887>',
|
||||
'SAR': '<:SAR:1067890949197414410>',
|
||||
'DEV': '<:DEV:1067891622727131248>'
|
||||
}
|
||||
|
||||
# Holds dictionary for race states to icons
|
||||
@ -710,6 +741,7 @@ class Robottas(commands.Bot):
|
||||
async def rbstop(ctx):
|
||||
self.is_reporting = False
|
||||
self.report_id = None
|
||||
await self.stop_collect()
|
||||
await ctx.send(":robot::peach: powering down")
|
||||
|
||||
|
||||
@ -778,6 +810,23 @@ class Robottas(commands.Bot):
|
||||
await self._test_file(ctx)
|
||||
|
||||
|
||||
@self.command()
|
||||
async def start_collect(ctx):
|
||||
if str(ctx.author) == "tamservo#0" or ctx.author.guild_permissions.administrator:
|
||||
# if an authorized user, start the collection script that
|
||||
# puts records into the database
|
||||
await self.start_collect()
|
||||
|
||||
|
||||
@self.command()
|
||||
async def calm(ctx):
|
||||
file_name = os.path.dirname(os.path.realpath(__file__))
|
||||
file_name = os.path.join(file_name, "images/calm.png")
|
||||
with open(file_name, "rb") as handle:
|
||||
df = discord.File(handle, filename=file_name)
|
||||
await ctx.send(file = df)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
rb = Robottas()
|
||||
rb.run_robottas()
|
||||
|
1
robottas_collector.py
Normal file → Executable file
1
robottas_collector.py
Normal file → Executable file
@ -1,3 +1,4 @@
|
||||
#!/usr/bin/python3
|
||||
import argparse
|
||||
import sys
|
||||
from RobottasSignalr import SignalRClient, messages_from_raw
|
||||
|
Loading…
x
Reference in New Issue
Block a user