def apiCompleteJob(authable): req = request.get_json(silent=True) try: job = Job.fromJson(req['job']) insertRes = env.gameApi.writeAnalysedGames(req['analysedGames']) if insertRes: env.queue.completeEngineAnalysis(job.playerId) player = env.irwin.env.playerDB.byId(job.playerId) analysedGames = env.irwin.env.analysedGameDB.byPlayerId( job.playerId) games = env.irwin.env.gameDB.byIds( [ag.gameId for ag in analysedGames]) predictions = env.irwin.analysedGameModel.predict([ GameAnalysedGame(ag, g) for ag, g in zip(analysedGames, games) if ag.gameLength() <= 60 ]) playerReport = PlayerReport.new(player, zip(analysedGames, predictions), owner=authable.name) logging.warning( f'Sending player report for {playerReport.playerId}, activation {playerReport.activation}%' ) env.lichessApi.postReport(playerReport) return Success except KeyError as e: tb = traceback.format_exc() logging.warning(f'Error completing job: {tb}') return BadRequest
def requestJob(self) -> Opt[Dict]: for i in range(5): try: result = requests.get(f'{self.env.url}/api/request_job', json={'auth': self.env.auth}) return Job.fromJson(result.json()) except (json.decoder.JSONDecodeError, requests.ConnectionError, requests.exceptions.SSLError): logging.warning( f"Error in request job. Trying again in 10 sec. Received: {result.text}" ) time.sleep(10) return None