Fix for funcom's roster delays.

Orgbots will run the roster 24 hours and 15 minutes after the last one funcom published on PORK; Onlinebots 24 hours and 10 minutes of the slowest roster maintained.
This commit is contained in:
2022-07-30 13:40:53 +02:00
parent c1196892ba
commit d4d08b3054
2 changed files with 20 additions and 0 deletions
@@ -199,6 +199,7 @@ class OrgController:
output = []
data = []
accounts = []
timestamp = 0
ours = self.db.query("SELECT o.org_id, a.org_name from orgs o "
"left join all_orgs a on o.org_id = a.org_id order by lower(a.org_name)")
for org in ours:
@@ -207,6 +208,9 @@ class OrgController:
self.cache.store('org_roster', f"{org.org_id}.5.json", json.dumps(result))
else:
result = json.loads(self.cache.retrieve('org_roster', f"{org.org_id}.5.json").data)
d = datetime.datetime.strptime(result[2] + " +0000", '%Y/%m/%d %H:%M:%S %z').timestamp()
if d > timestamp:
timestamp = d
for char_info in result[1]:
data.append((char_info["CHAR_INSTANCE"], char_info["NAME"], char_info["FIRSTNAME"],
@@ -288,6 +292,13 @@ class OrgController:
self.logger.info(
f"Successfully fetched {len(data)} players from {len(ours)} orgs "
f"in {time.time() - start:.2f} seconds. - ")
while (timestamp + 24 * 60 * 60) < datetime.datetime.now().timestamp():
timestamp += 24 * 60 * 60
self.db.exec("UPDATE timer_event SET next_run=? WHERE handler=? AND event_sub_type=?", [
int(timestamp +24*60*60 + 10*60),
"modules.onlinebot.online.org_controller.OrgController.fetch_orgs",
86400
])
del self.threads['roster']
if "roster" not in self.threads.keys():
@@ -1,3 +1,4 @@
import datetime
import json
import time
import typing
@@ -196,6 +197,14 @@ class OrgRosterController:
[self.public_channel_service.org_id])
conn.commit()
self.bot.send_org_message('Successfully updated the roster.')
d = datetime.datetime.strptime(result[2] + " +0000", '%Y/%m/%d %H:%M:%S %z').timestamp()
while (d + 24*60*60) < datetime.datetime.now().timestamp():
d += 24*60*60
self.db.exec("UPDATE timer_event SET next_run=? WHERE handler=? AND event_sub_type=?", [
int(d+24*60*60 + 15*60),
"modules.orgbot.org.org_roster_controller.OrgRosterController.update_roster",
86400
])
@event(PublicChannelService.ORG_MSG_EVENT, "Update org roster when characters join or leave", is_hidden=True)
def org_msg_event(self, _, event_data):