Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 81c93ac

Browse files
authored
Merge pull request #3 from sqlballs/adding-notebook
Adding notebook
2 parents 3f529bd + 7754981 commit 81c93ac

File tree

3 files changed

+213
-1
lines changed

3 files changed

+213
-1
lines changed
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"source": [
6+
"# Replace with your actual item ID\n",
7+
"item_id = \"\" #datapipeline\n",
8+
"#item_id = \"\" #copyjob"
9+
],
10+
"outputs": [],
11+
"execution_count": null,
12+
"metadata": {
13+
"microsoft": {
14+
"language": "python",
15+
"language_group": "synapse_pyspark"
16+
},
17+
"tags": [
18+
"parameters"
19+
]
20+
},
21+
"id": "196c5c86-4789-4f75-87aa-27741b6522d5"
22+
},
23+
{
24+
"cell_type": "code",
25+
"source": [
26+
"import requests\n",
27+
"import json\n",
28+
"import sempy.fabric as fabric\n",
29+
"\n",
30+
"\n",
31+
"# Get the current workspace ID dynamically\n",
32+
"workspace_id = fabric.get_notebook_workspace_id()\n",
33+
"\n",
34+
"# Get the current user's access token\n",
35+
"access_token = notebookutils.credentials.getToken('pbi')\n",
36+
"\n",
37+
"# Construct the API URL Jobs Instances\n",
38+
"url = f\"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/items/{item_id}/jobs/instances\"\n",
39+
"\n",
40+
"\n",
41+
"# Set headers\n",
42+
"headers = {\n",
43+
" \"Authorization\": f\"Bearer {access_token}\",\n",
44+
" \"Content-Type\": \"application/json\"\n",
45+
"}\n",
46+
"\n",
47+
"# Make the API request\n",
48+
"response = requests.get(url, headers=headers)\n",
49+
"\n",
50+
"\n",
51+
"# Check and process the response\n",
52+
"if response.status_code == 200:\n",
53+
" data = response.json()\n",
54+
" job_instances = data.get(\"value\", []) # Extract the list of job instances\n",
55+
" if job_instances:\n",
56+
" \n",
57+
" json_lines = [json.dumps(job_instances) for job_instance in job_instances]\n",
58+
" \n",
59+
" df = spark.read.json(spark.sparkContext.parallelize(json_lines))\n",
60+
" #print('df about to run')\n",
61+
" #df.show(truncate=False)\n",
62+
" #display(df)\n",
63+
" else:\n",
64+
" print(\"No job instances found.\")\n",
65+
"else:\n",
66+
" print(f\"Failed to fetch job status: {response.status_code} - {response.text}\")\n"
67+
],
68+
"outputs": [],
69+
"execution_count": null,
70+
"metadata": {
71+
"microsoft": {
72+
"language": "python",
73+
"language_group": "synapse_pyspark"
74+
},
75+
"collapsed": false
76+
},
77+
"id": "0da9ff9f-d002-4c9f-b117-ddc6b3b153ab"
78+
},
79+
{
80+
"cell_type": "code",
81+
"source": [
82+
"from pyspark.sql.functions import col\n",
83+
"from pyspark.sql.types import TimestampType\n",
84+
"\n",
85+
"# Ensure startTimeUtc is in timestamp format\n",
86+
"df = df.withColumn(\"startTimeUtc\", col(\"startTimeUtc\").cast(TimestampType()))\n",
87+
"\n",
88+
"# Sort by startTimeUtc descending\n",
89+
"df_sorted = df.orderBy(col(\"startTimeUtc\").desc())\n",
90+
"\n",
91+
"# Filter out rows where status is 'Deduped'\n",
92+
"df_filtered = df_sorted.filter(col(\"status\") != \"Deduped\")\n",
93+
"\n",
94+
"# Get the first non-Deduped status\n",
95+
"latest_status = df_filtered.select(\"status\").first()[\"status\"]\n",
96+
"\n",
97+
"#print(f\"The latest non-Deduped status is: {latest_status}\")\n"
98+
],
99+
"outputs": [],
100+
"execution_count": null,
101+
"metadata": {
102+
"microsoft": {
103+
"language": "python",
104+
"language_group": "synapse_pyspark"
105+
}
106+
},
107+
"id": "815a3cc8-e93b-4679-971f-d4d41081ea57"
108+
},
109+
{
110+
"cell_type": "code",
111+
"source": [
112+
"notebookutils.notebook.exit(latest_status)"
113+
],
114+
"outputs": [],
115+
"execution_count": null,
116+
"metadata": {
117+
"microsoft": {
118+
"language": "python",
119+
"language_group": "synapse_pyspark"
120+
}
121+
},
122+
"id": "34903b61-df71-47d6-9e1d-cf643983ddfc"
123+
}
124+
],
125+
"metadata": {
126+
"kernel_info": {
127+
"name": "synapse_pyspark"
128+
},
129+
"kernelspec": {
130+
"name": "synapse_pyspark",
131+
"display_name": "synapse_pyspark"
132+
},
133+
"language_info": {
134+
"name": "python"
135+
},
136+
"microsoft": {
137+
"language": "python",
138+
"language_group": "synapse_pyspark",
139+
"ms_spell_check": {
140+
"ms_spell_check_language": "en"
141+
}
142+
},
143+
"nteract": {
144+
"version": "[email protected]"
145+
},
146+
"synapse_widget": {
147+
"version": "0.1",
148+
"state": {}
149+
},
150+
"spark_compute": {
151+
"compute_id": "/trident/default",
152+
"session_options": {
153+
"conf": {
154+
"spark.synapse.nbs.session.timeout": "1200000"
155+
}
156+
}
157+
},
158+
"dependencies": {
159+
"lakehouse": {
160+
"known_lakehouses": [
161+
{
162+
"id": ""
163+
}
164+
],
165+
"default_lakehouse": "",
166+
"default_lakehouse_name": "",
167+
"default_lakehouse_workspace_id": ""
168+
}
169+
}
170+
},
171+
"nbformat": 4,
172+
"nbformat_minor": 5
173+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Find Status of Jobs
2+
3+
This repository contains a Microsoft Fabric notebook that demonstrates how to use the **List Item Job Instances** API to find the status of jobs within Fabric.
4+
5+
## πŸ” Overview
6+
7+
The notebook leverages the https://learn.microsoft.com/en-us/rest/api/fabric/core/job-scheduler/list-item-job-instances to retrieve job execution details. This is particularly useful for monitoring and diagnostics in Fabric-based solutions.
8+
9+
## πŸ““ Notebook Author
10+
11+
This notebook was created by **Bradley Ball**, a Sr. Cloud Solution Architect and host of the *Tales from the Field* YouTube channel.
12+
13+
## πŸŽ₯ Watch the Video
14+
15+
You can watch the full walkthrough and explanation of this notebook on YouTube:
16+
17+
<p><a href="https://www.youtube.com/watch?v=TSTeoeCNh7c"><img src="https://img.youtube.com/vi/TSTeoeCNh7c/0.jpg" height = 200></a>
18+
19+
## πŸ“‚ Contents
20+
21+
- `FindStatusOfJobs.ipynb`: The main notebook that demonstrates how to call the API and interpret the results.
22+
- `README.md`: This file.
23+
24+
## πŸ“Œ Prerequisites
25+
26+
- Access to Microsoft Fabric
27+
- Proper authentication setup to call Fabric REST APIs
28+
- Familiarity with notebooks in Microsoft Fabric
29+
30+
## πŸ› οΈ How to Use
31+
32+
1. Open the notebook in Microsoft Fabric.
33+
2. Follow the instructions to authenticate and run the API call.
34+
3. Review the returned job instance data for insights into job execution.
35+
36+
## πŸ“„ Documentation
37+
For more details on the API used, refer to the official Microsoft documentation:
38+
πŸ‘‰ ([List Item Job Instances API](https://learn.microsoft.com/en-us/rest/api/fabric/core/job-scheduler/list-item-job-instances) with ❀️ by Bradley Ball)
39+
> https://www.youtube.com/@TalesFromTheField
40+

β€ŽMicrosoft Fabric/Find Status of Jobs/readme.meβ€Ž

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
Β (0)