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+ 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+ }
0 commit comments