예제 #1
0
파일: Api.py 프로젝트: alice-gottlieb/grail
 def completeJob(self, job: Job,
                 analysedGames: List[AnalysedGame]) -> Opt[Response]:
     payload = {
         'auth': self.env.auth,
         'job': job.toJson(),
         'analysedGames': [ag.toJson() for ag in analysedGames]
     }
     for i in range(5):
         try:
             result = requests.post(f'{self.env.url}/api/complete_job',
                                    json=payload)
             return result
         except (json.decoder.JSONDecodeError, requests.ConnectionError,
                 requests.exceptions.SSLError):
             logging.warning(
                 'Error in completing job. Trying again in 10 sec')
             time.sleep(10)
     return None
예제 #2
0
    def apiRequestJob(authable):
        engineQueue = env.queue.nextEngineAnalysis(authable.id)
        logging.debug(f'EngineQueue for req {engineQueue}')
        if engineQueue is not None:
            games = env.gameApi.gamesByIds(engineQueue.requiredGameIds)

            logging.warning(
                f'Requesting {authable.name} analyses {engineQueue.requiredGameIds} for {engineQueue.id}'
            )

            job = Job(playerId=engineQueue.id,
                      games=games,
                      analysedPositions=[])

            logging.info(f'Job: {job}')

            return Response(response=json.dumps(job.toJson()),
                            status=200,
                            mimetype='application/json')
        return NotAvailable