|
| 1 | +import app from "../../cloud_convert.app.mjs"; |
| 2 | +import utils from "../../common/utils.mjs"; |
| 3 | + |
| 4 | +export default { |
| 5 | + key: "cloud_convert-create-job", |
| 6 | + name: "Create Job", |
| 7 | + description: "Creates a new job for one or more tasks. [See the documentation](https://cloudconvert.com/api/v2/jobs#jobs-create)", |
| 8 | + version: "0.0.1", |
| 9 | + type: "action", |
| 10 | + annotations: { |
| 11 | + readOnlyHint: false, |
| 12 | + destructiveHint: false, |
| 13 | + openWorldHint: true, |
| 14 | + }, |
| 15 | + props: { |
| 16 | + app, |
| 17 | + tasks: { |
| 18 | + type: "object", |
| 19 | + label: "Tasks", |
| 20 | + description: `An object containing named tasks that form the job workflow. You can name tasks however you want, but **only alphanumeric characters, hyphens (-), and underscores (_) are allowed**. |
| 21 | +
|
| 22 | +**Each task object must include:** |
| 23 | +
|
| 24 | +- \`operation\` (string, **required**): The endpoint for creating the task (e.g., \`convert\`, \`import/url\`, \`import/s3\`, \`export/s3\`, etc.) |
| 25 | +- \`input\` (string or array, optional): The name(s) of the input task(s). Use this to reference other tasks within the same job. Multiple task names can be provided as an array. |
| 26 | +- \`ignore_error\` (boolean, optional): By default, the job fails if one task fails. Set to \`true\` to continue the job even if this specific task fails. |
| 27 | +- Task-specific options (optional): Additional parameters that depend on the \`operation\` type. These are the same parameters used when creating the task via its direct endpoint. |
| 28 | +
|
| 29 | +**Example:** |
| 30 | +\`\`\`json |
| 31 | +{ |
| 32 | + "import-my-file": { |
| 33 | + "operation": "import/url", |
| 34 | + "url": "https://example.com/document.pdf" |
| 35 | + }, |
| 36 | + "convert-my-file": { |
| 37 | + "operation": "convert", |
| 38 | + "input": "import-my-file", |
| 39 | + "output_format": "jpg", |
| 40 | + "pages": "1-3" |
| 41 | + }, |
| 42 | + "export-my-file": { |
| 43 | + "operation": "export/url", |
| 44 | + "input": ["convert-my-file"] |
| 45 | + } |
| 46 | +} |
| 47 | +\`\`\` |
| 48 | +
|
| 49 | +[See the tasks documentation](https://cloudconvert.com/api/v2/tasks)`, |
| 50 | + }, |
| 51 | + tag: { |
| 52 | + type: "string", |
| 53 | + label: "Tag", |
| 54 | + description: "An arbitrary string to identify the job. Does not have any effect and can be used to associate with your application", |
| 55 | + optional: true, |
| 56 | + }, |
| 57 | + webhookUrl: { |
| 58 | + type: "string", |
| 59 | + label: "Webhook URL", |
| 60 | + description: "Single-job webhook URL receiving `job.finished` or `job.failed` events", |
| 61 | + optional: true, |
| 62 | + }, |
| 63 | + }, |
| 64 | + async run({ $ }) { |
| 65 | + const { |
| 66 | + app, |
| 67 | + tasks, |
| 68 | + tag, |
| 69 | + webhookUrl, |
| 70 | + } = this; |
| 71 | + |
| 72 | + const response = await app.createJob({ |
| 73 | + $, |
| 74 | + data: { |
| 75 | + tasks: utils.parseJson(tasks), |
| 76 | + tag, |
| 77 | + webhook_url: webhookUrl, |
| 78 | + }, |
| 79 | + }); |
| 80 | + |
| 81 | + $.export("$summary", `Successfully created job with ID \`${response.data.id}\``); |
| 82 | + return response; |
| 83 | + }, |
| 84 | +}; |
0 commit comments