def game(script: str, class_name: str, args: dict) -> status: status, connection = Connection.get_connection() if status != 200: return status env = Environment(connection.http_server_url) module = importlib.import_module(f'scripts.{script}') Agent = getattr(module, class_name) agent = Agent() env.play(agent, **args)
def allocate_workgroup(worker_id: str) -> status: status, connection = Connection.get_connection() if status != 200: return status http_transport = RequestsHTTPTransport( url=connection.http_server_url, headers={'Authorization': connection.server_private_key}, verify=False, retries=3) with Client(transport=http_transport, fetch_schema_from_transport=True) as session: session.execute(gql(ALLOCATE_WORKGROUP(worker_id))) try: workgroup = Workgroup.objects.get(worker_id=worker_id) if workgroup.status == WorkgroupStatus.BUSY: return 400 workgroup.status = WorkgroupStatus.BUSY workgroup.save() except ObjectDoesNotExist: Workgroup(worker_id=worker_id).save() return 200