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