{ "cells": [ { "cell_type": "markdown", "id": "39974b18", "metadata": {}, "source": [ "# Connect and access the job queue" ] }, { "cell_type": "markdown", "id": "b24d44be", "metadata": {}, "source": [ "This example shows how to connect to Granta MI and access the job queue. For more information\n", "on creating and interacting with jobs, see the subsequent examples." ] }, { "cell_type": "markdown", "id": "38bd257d", "metadata": {}, "source": [ "## Connect to Granta MI" ] }, { "cell_type": "markdown", "id": "f26e463a", "metadata": {}, "source": [ "First, use the ``ansys.grantami.jobqueue.Connection`` class to connect to the Granta MI\n", "server. The ``Connection`` class uses a fluent interface to build the connection, which is always\n", "invoked in the following sequence:\n", "\n", "1. Specify the URL for your Granta MI service layer as a parameter to the ``Connection`` class.\n", "2. Specify the authentication method using a ``Connection.with_*()`` method.\n", "3. Use the ``Connection.connect()`` method to finalize the connection.\n", "\n", "This returns an ``ansys.grantami.jobqueue.JobQueueApiClient`` object, which is called ``client``\n", "in these examples." ] }, { "cell_type": "code", "execution_count": null, "id": "3f40ed63", "metadata": { "tags": [] }, "outputs": [], "source": [ "from ansys.grantami.jobqueue import Connection\n", "\n", "server_url = \"http://my_grantami_server/mi_servicelayer\"" ] }, { "cell_type": "markdown", "id": "7ca23458", "metadata": {}, "source": [ "If you are running your Python script on Windows, you are generally able to use ``.with_autologon()``." ] }, { "cell_type": "code", "execution_count": null, "id": "7c71e8a1", "metadata": { "tags": [] }, "outputs": [], "source": [ "client = Connection(server_url).with_autologon().connect()\n", "client" ] }, { "cell_type": "markdown", "id": "013be0f6", "metadata": {}, "source": [ "If the Python script is running on Linux without Kerberos enabled, or you want to use an account\n", "other than your logged-in account, you can specify credentials explicitly." ] }, { "cell_type": "code", "execution_count": null, "id": "def03391", "metadata": { "tags": [] }, "outputs": [], "source": [ "client = Connection(server_url).with_credentials(\"my_username\", \"my_password\").connect()\n", "client" ] }, { "cell_type": "markdown", "id": "8e60686c", "metadata": {}, "source": [ "OIDC and anonymous authentication methods are also available, but they are beyond the scope of\n", "this example. For more information, see the PyAnsys [OpenAPI-Common documentation](https://github.com/pyansys/openapi-common)." ] }, { "cell_type": "markdown", "id": "f0827693", "metadata": {}, "source": [ "## Access the job queue\n", "You use the ``client`` object to determine the activities that you can perform with the job queue." ] }, { "cell_type": "code", "execution_count": null, "id": "abcb8a31", "metadata": { "tags": [] }, "outputs": [], "source": [ "f\"The current user is an administrator: {client.is_admin_user}\"" ] }, { "cell_type": "code", "execution_count": null, "id": "241ff861", "metadata": { "tags": [] }, "outputs": [], "source": [ "f\"The current user can write jobs: {client.can_write_job}\"" ] }, { "cell_type": "markdown", "id": "3523aa15", "metadata": {}, "source": [ "You can also access information on how the job queue processes jobs." ] }, { "cell_type": "code", "execution_count": null, "id": "881a28bf", "metadata": {}, "outputs": [], "source": [ "f\"Concurrency enabled: {'Yes' if client.processing_configuration.concurrency else 'No'}\"" ] }, { "cell_type": "markdown", "id": "aefda064", "metadata": {}, "source": [ "Finally, you can access the job queue itself. The job queue might be empty if no\n", "jobs have been submitted recently.)" ] }, { "cell_type": "code", "execution_count": null, "id": "1f06e95e", "metadata": {}, "outputs": [], "source": [ "client.jobs" ] }, { "cell_type": "markdown", "id": "6fa547d5", "metadata": {}, "source": [ "Note: The jobs accessible in the queue depend on the user's role.\n", "Standard users can only access their own jobs, whereas administrator users\n", "can access jobs created by all users." ] } ], "metadata": { "jupytext": { "formats": "ipynb,py:light" }, "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" } }, "nbformat": 4, "nbformat_minor": 5 }