async def sample_list_all_submitted_jobs_async(): import os # [START list_all_jobs_async] from azure.core.credentials import AzureKeyCredential from azure.ai.translation.document.aio import DocumentTranslationClient endpoint = os.environ["AZURE_DOCUMENT_TRANSLATION_ENDPOINT"] key = os.environ["AZURE_DOCUMENT_TRANSLATION_KEY"] client = DocumentTranslationClient(endpoint, AzureKeyCredential(key)) async with client: translation_jobs = client.list_submitted_jobs() # type: AsyncItemPaged[JobStatusResult] async for job in translation_jobs: if job.status == "Running": job = await client.wait_until_done(job.id) print("Job ID: {}".format(job.id)) print("Job status: {}".format(job.status)) print("Job created on: {}".format(job.created_on)) print("Job last updated on: {}".format(job.last_updated_on)) print("Total number of translations on documents: {}".format(job.documents_total_count)) print("Total number of characters charged: {}".format(job.total_characters_charged)) print("\nOf total documents...") print("{} failed".format(job.documents_failed_count)) print("{} succeeded".format(job.documents_succeeded_count)) print("{} cancelled\n".format(job.documents_cancelled_count))
async def sample_list_submitted_jobs_with_filters_async(): # import libraries from azure.core.credentials import AzureKeyCredential from azure.ai.translation.document.aio import DocumentTranslationClient from datetime import datetime # obtain client secrets endpoint = os.environ["AZURE_DOCUMENT_TRANSLATION_ENDPOINT"] key = os.environ["AZURE_DOCUMENT_TRANSLATION_KEY"] # authorize client client = DocumentTranslationClient(endpoint, AzureKeyCredential(key)) async with client: # set your filters ''' Note: these are just sample values for the filters! please comment/uncomment/change what you are interested in using. ''' start = datetime(2021, 4, 12) end = datetime(2021, 4, 14) statuses = ["Cancelled", "Failed"] order_by = ["createdDateTimeUtc desc"] results_per_page = 2 skip = 3 # list jobs submitted_jobs = client.list_submitted_jobs( # filters statuses=statuses, created_after=start, created_before=end, # ordering order_by=order_by, # paging skip=skip, results_per_page=results_per_page ).by_page() # check statuses async for page in submitted_jobs: async for job in page: display_job_info(job)