Skip to content

Commit a422717

Browse files
committed
Databricks API - Jobs action components
1 parent 87bef6a commit a422717

File tree

18 files changed

+933
-16
lines changed

18 files changed

+933
-16
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import app from "../../databricks.app.mjs";
2+
3+
export default {
4+
key: "databricks-cancel-all-runs",
5+
name: "Cancel All Runs",
6+
description: "Cancel all active runs for a job. The runs are canceled asynchronously, so it doesn't prevent new runs from being started. [See the documentation](https://docs.databricks.com/api/workspace/jobs/cancelallruns)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
// eslint-disable-next-line pipedream/props-label, pipedream/props-description
12+
info: {
13+
type: "alert",
14+
alertType: "info",
15+
content: "Either a **Job** or **All Queued Runs** must be provided.",
16+
},
17+
jobId: {
18+
optional: true,
19+
propDefinition: [
20+
app,
21+
"jobId",
22+
],
23+
},
24+
allQueuedRuns: {
25+
type: "boolean",
26+
label: "All Queued Runs",
27+
description: "Optional boolean parameter to cancel all queued runs. If no **Job ID** is provided, all queued runs in the workspace are canceled.",
28+
optional: true,
29+
},
30+
},
31+
async run({ $ }) {
32+
const {
33+
app,
34+
jobId,
35+
allQueuedRuns,
36+
} = this;
37+
38+
await app.cancelAllRuns({
39+
$,
40+
data: {
41+
job_id: jobId,
42+
all_queued_runs: allQueuedRuns,
43+
},
44+
});
45+
46+
$.export("$summary", "Successfully initiated cancellation of all runs");
47+
48+
return {
49+
success: true,
50+
};
51+
},
52+
};
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import app from "../../databricks.app.mjs";
2+
3+
export default {
4+
key: "databricks-cancel-run",
5+
name: "Cancel Run",
6+
description: "Cancel a job run. The run is canceled asynchronously, so it may still be running when this request completes. [See the documentation](https://docs.databricks.com/api/workspace/jobs/cancelrun)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
runId: {
12+
propDefinition: [
13+
app,
14+
"runId",
15+
],
16+
},
17+
},
18+
async run({ $ }) {
19+
const {
20+
app,
21+
runId,
22+
} = this;
23+
24+
await app.cancelRun({
25+
$,
26+
data: {
27+
run_id: runId,
28+
},
29+
});
30+
31+
$.export("$summary", `Successfully initiated cancellation of run with ID \`${runId}\`.`);
32+
33+
return {
34+
success: true,
35+
};
36+
},
37+
};
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
import app from "../../databricks.app.mjs";
2+
import utils from "../../common/utils.mjs";
3+
4+
export default {
5+
key: "databricks-create-job",
6+
name: "Create Job",
7+
description: "Create a job. [See the documentation](https://docs.databricks.com/api/workspace/jobs/create)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
app,
12+
tasks: {
13+
type: "string[]",
14+
label: "Tasks",
15+
description: `A list of task specifications to be executed by this job. JSON string format. [See the API documentation](https://docs.databricks.com/api/workspace/jobs/create#tasks) for task specification details.
16+
17+
**Example:**
18+
\`\`\`json
19+
[
20+
{
21+
"notebook_task": {
22+
"notebook_path": "/Workspace/Users/[email protected]/weather_ingest"
23+
},
24+
"task_key": "weather_ocean_data"
25+
}
26+
]
27+
\`\`\`
28+
`,
29+
},
30+
name: {
31+
type: "string",
32+
label: "Job Name",
33+
description: "An optional name for the job",
34+
optional: true,
35+
},
36+
tags: {
37+
type: "object",
38+
label: "Tags",
39+
description: "A map of tags associated with the job. These are forwarded to the cluster as cluster tags for jobs clusters, and are subject to the same limitations as cluster tags",
40+
optional: true,
41+
},
42+
jobClusters: {
43+
type: "string[]",
44+
label: "Job Clusters",
45+
description: "A list of job cluster specifications that can be shared and reused by tasks of this job. JSON string format. [See the API documentation](https://docs.databricks.com/api/workspace/jobs/create#job_clusters) for job cluster specification details",
46+
optional: true,
47+
},
48+
emailNotifications: {
49+
type: "string",
50+
label: "Email Notifications",
51+
description: "An optional set of email addresses that is notified when runs of this job begin or complete as well as when this job is deleted. JSON string format. [See the API documentation](https://docs.databricks.com/api/workspace/jobs/create#email_notifications) for email notification specification details",
52+
optional: true,
53+
},
54+
webhookNotifications: {
55+
type: "string",
56+
label: "Webhook Notifications",
57+
description: "A collection of system notification IDs to notify when the run begins or completes. JSON string format. [See the API documentation](https://docs.databricks.com/api/workspace/jobs/create#webhook_notifications) for webhook notification specification details",
58+
optional: true,
59+
},
60+
timeoutSeconds: {
61+
type: "integer",
62+
label: "Timeout Seconds",
63+
description: "An optional timeout applied to each run of this job. The default behavior is to have no timeout",
64+
optional: true,
65+
},
66+
schedule: {
67+
type: "string",
68+
label: "Schedule",
69+
description: "An optional periodic schedule for this job. The default behavior is that the job only runs when triggered by clicking **Run Now** in the Jobs UI or sending an API request to runNow. JSON string format. [See the API documentation](https://docs.databricks.com/api/workspace/jobs/create#schedule) for schedule specification details",
70+
optional: true,
71+
},
72+
maxConcurrentRuns: {
73+
type: "integer",
74+
label: "Max Concurrent Runs",
75+
description: "An optional maximum allowed number of concurrent runs of the job. Defaults to 1",
76+
optional: true,
77+
},
78+
gitSource: {
79+
type: "string",
80+
label: "Git Source",
81+
description: "An optional specification for a remote repository containing the notebooks used by this job's notebook tasks. JSON string format. [See the API documentation](https://docs.databricks.com/api/workspace/jobs/create#git_source) for git source specification details",
82+
optional: true,
83+
},
84+
accessControlList: {
85+
type: "string[]",
86+
label: "Access Control List",
87+
description: "List of permissions to set on the job. JSON string format. [See the API documentation](https://docs.databricks.com/api/workspace/jobs/create#access_control_list) for access control list specification details",
88+
optional: true,
89+
},
90+
},
91+
async run({ $ }) {
92+
const {
93+
app,
94+
tasks,
95+
name,
96+
tags,
97+
jobClusters,
98+
emailNotifications,
99+
webhookNotifications,
100+
timeoutSeconds,
101+
schedule,
102+
maxConcurrentRuns,
103+
gitSource,
104+
accessControlList,
105+
} = this;
106+
107+
const response = await app.createJob({
108+
$,
109+
data: {
110+
name,
111+
tags,
112+
tasks: utils.parseJsonInput(tasks),
113+
job_clusters: utils.parseJsonInput(jobClusters),
114+
email_notifications: utils.parseJsonInput(emailNotifications),
115+
webhook_notifications: utils.parseJsonInput(webhookNotifications),
116+
timeout_seconds: timeoutSeconds,
117+
schedule: utils.parseJsonInput(schedule),
118+
max_concurrent_runs: maxConcurrentRuns,
119+
git_source: utils.parseJsonInput(gitSource),
120+
access_control_list: utils.parseJsonInput(accessControlList),
121+
},
122+
});
123+
124+
$.export("$summary", `Successfully created job with ID \`${response.job_id}\``);
125+
126+
return response;
127+
},
128+
};
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import app from "../../databricks.app.mjs";
2+
3+
export default {
4+
key: "databricks-delete-job",
5+
name: "Delete Job",
6+
description: "Delete a job. Deleted jobs cannot be recovered. [See the documentation](https://docs.databricks.com/api/workspace/jobs/delete)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
jobId: {
12+
propDefinition: [
13+
app,
14+
"jobId",
15+
],
16+
},
17+
},
18+
async run({ $ }) {
19+
const {
20+
app,
21+
jobId,
22+
} = this;
23+
24+
await app.deleteJob({
25+
$,
26+
data: {
27+
job_id: jobId,
28+
},
29+
});
30+
31+
$.export("$summary", `Successfully deleted job with ID \`${jobId}\`.`);
32+
33+
return {
34+
success: true,
35+
};
36+
},
37+
};
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import app from "../../databricks.app.mjs";
2+
3+
export default {
4+
key: "databricks-delete-run",
5+
name: "Delete Run",
6+
description: "Delete a non-active run. Returns an error if the run is active. [See the documentation](https://docs.databricks.com/api/workspace/jobs/deleterun)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
runId: {
12+
propDefinition: [
13+
app,
14+
"runId",
15+
],
16+
},
17+
},
18+
async run({ $ }) {
19+
const response = await this.app.deleteRun({
20+
data: {
21+
run_id: this.runId,
22+
},
23+
$,
24+
});
25+
26+
$.export("$summary", `Successfully deleted run with ID ${this.runId}.`);
27+
28+
return response || {};
29+
},
30+
};
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import app from "../../databricks.app.mjs";
2+
3+
export default {
4+
key: "databricks-export-run",
5+
name: "Export Run",
6+
description: "Export and retrieve the job run task. [See the documentation](https://docs.databricks.com/api/workspace/jobs/exportrun)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
runId: {
12+
propDefinition: [
13+
app,
14+
"runId",
15+
],
16+
},
17+
viewsToExport: {
18+
type: "string",
19+
label: "Views to Export",
20+
description: "Which views to export. Defaults to `CODE`",
21+
optional: true,
22+
options: [
23+
"CODE",
24+
"DASHBOARDS",
25+
"ALL",
26+
],
27+
},
28+
},
29+
async run({ $ }) {
30+
const {
31+
app,
32+
runId,
33+
viewsToExport,
34+
} = this;
35+
36+
const response = await app.exportRun({
37+
$,
38+
params: {
39+
run_id: runId,
40+
views_to_export: viewsToExport,
41+
},
42+
});
43+
44+
$.export("$summary", `Successfully exported run with ID \`${runId}\`.`);
45+
46+
return response;
47+
},
48+
};
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import app from "../../databricks.app.mjs";
2+
3+
export default {
4+
key: "databricks-get-job-permissions",
5+
name: "Get Job Permissions",
6+
description: "Get permissions of a job. [See the documentation](https://docs.databricks.com/api/workspace/jobs/getpermissions)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
jobId: {
12+
propDefinition: [
13+
app,
14+
"jobId",
15+
],
16+
},
17+
},
18+
async run({ $ }) {
19+
const {
20+
app,
21+
jobId,
22+
} = this;
23+
24+
const response = await app.getJobPermissions({
25+
$,
26+
jobId,
27+
});
28+
29+
$.export("$summary", `Successfully retrieved permissions for job with ID \`${jobId}\`.`);
30+
31+
return response;
32+
},
33+
};

0 commit comments

Comments
 (0)