-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added list_item_job_instances, ran black
- Loading branch information
1 parent
54df7aa
commit fd24369
Showing
26 changed files
with
242 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import sempy.fabric as fabric | ||
import pandas as pd | ||
from typing import Optional | ||
from sempy_labs._helper_functions import ( | ||
resolve_workspace_name_and_id, | ||
resolve_item_name_and_id, | ||
pagination, | ||
) | ||
from sempy.fabric.exceptions import FabricHTTPException | ||
from uuid import UUID | ||
|
||
|
||
def list_item_job_instances( | ||
item: str | UUID, type: Optional[str] = None, workspace: Optional[str | UUID] = None | ||
) -> pd.DataFrame: | ||
""" | ||
Returns a list of job instances for the specified item. | ||
This is a wrapper function for the following API: `Job Scheduler - List Item Job Instances <https://learn.microsoft.com/rest/api/fabric/core/job-scheduler/list-item-job-instances>`_. | ||
Parameters | ||
---------- | ||
item : str | UUID | ||
The item name or ID | ||
type : str, default=None | ||
The item type. If specifying the item name as the item, the item type is required. | ||
workspace : str | UUID, default=None | ||
The Fabric workspace name or ID used by the lakehouse. | ||
Defaults to None which resolves to the workspace of the attached lakehouse | ||
or if no lakehouse attached, resolves to the workspace of the notebook. | ||
Returns | ||
------- | ||
pandas.DataFrame | ||
Shows a list of job instances for the specified item. | ||
""" | ||
|
||
(workspace_name, workspace_id) = resolve_workspace_name_and_id(workspace) | ||
(item_name, item_id) = resolve_item_name_and_id( | ||
item=item, type=type, workspace=workspace | ||
) | ||
|
||
client = fabric.FabricRestClient() | ||
response = client.get( | ||
f"v1/workspaces/{workspace_id}/items/{item_id}/jobs/instances" | ||
) | ||
|
||
if response.status_code != 200: | ||
raise FabricHTTPException(response) | ||
|
||
df = pd.DataFrame( | ||
columns=[ | ||
"Job Instance Id", | ||
"Item Id", | ||
"Job Type", | ||
"Invoke Type", | ||
"Status", | ||
"Root Activity Id" "Start Time UTC", | ||
"End Time UTC", | ||
"Failure Reason", | ||
] | ||
) | ||
|
||
responses = pagination(client, response) | ||
|
||
if not responses[0].get("value"): | ||
return df | ||
|
||
dfs = [] | ||
for r in responses: | ||
for v in r.get("value", []): | ||
new_data = { | ||
"Job Instance Id": v.get("id"), | ||
"Item Id": v.get("itemId"), | ||
"Job Type": v.get("jobType"), | ||
"Invoke Type": v.get("invokeType"), | ||
"Status": v.get("status"), | ||
"Root Activity Id": v.get("rootActivityId"), | ||
"Start Time UTC": v.get("startTimeUtc"), | ||
"End Time UTC": v.get("endTimeUtc"), | ||
"Failure Reason": v.get("failureReason"), | ||
} | ||
dfs.append(pd.DataFrame(new_data, index=[0])) | ||
|
||
if dfs: | ||
df = pd.concat(dfs, ignore_index=True) | ||
|
||
return df |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.