First pass on username update background task

doc_update
Joey Hines 2018-12-15 16:00:45 -06:00
parent a4d71858bf
commit 7dc93e4439
4 changed files with 25 additions and 2 deletions

View File

@ -1,7 +1,7 @@
from django.db.models import Q, F from django.db.models import Q, F
from GeoffreyApp.models import * from GeoffreyApp.models import *
from GeoffreyApp.api.BotErrors import * from GeoffreyApp.api.BotErrors import *
from GeoffreyApp.api.MinecraftAccountInfoGrabber import * from GeoffreyApp.minecraft_api import *
post_list = [] post_list = []
get_list = [] get_list = []

View File

@ -11,7 +11,9 @@ class GeoffreyAppConfig(AppConfig):
verbose_name = "Geoffrey: Minecraft Web Database" verbose_name = "Geoffrey: Minecraft Web Database"
def ready(self): def ready(self):
subprocess.run('screen -X -S "{0}" quit'.format("geoffrey"), shell=True) import GeoffreyApp.background_tasks as background_tasks
background_tasks.run_tasks()
#subprocess.run('screen -X -S "{0}" quit'.format("geoffrey"), shell=True)
#subprocess.run( #subprocess.run(
# 'screen -S geoffrey -d -m {} {}'.format(sys.executable, path), # 'screen -S geoffrey -d -m {} {}'.format(sys.executable, path),
# shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) # shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

View File

@ -0,0 +1,21 @@
from GeoffreyApp.models import Player
from GeoffreyApp.minecraft_api import grab_playername
from apscheduler.schedulers.background import BackgroundScheduler
def update_usernames():
players = Player.objects.all()
for player in players:
mc_username = grab_playername(player.mc_uuid)
if player.name != mc_username:
player.name = mc_username
player.save()
def run_tasks():
scheduler = BackgroundScheduler()
scheduler.add_job(update_usernames, 'interval', minutes=10)
scheduler.start()