이 문서에서는 특정 작업이 성공하거나 실패할 때까지 예약되지 않는 작업을 만들고 실행하는 방법을 설명합니다. 작업 상태에 대해 자세히 알아보려면 작업 생성 및 실행 개요를 참고하세요.
리소스 요구사항이 다양한 워크로드가 있는 경우 종속 작업을 사용하여 각각 별도의 VM을 사용하는 자동화된 작업 체인을 만드는 것이 좋습니다.
예를 들어 수요가 낮은 작업(예: 데이터 준비)과 컴퓨팅 집약적 작업 (예: 데이터 처리)에 사용되는 VM 유형을 분리합니다.
종속 작업을 사용하여 리소스 소비를 최적화하면 비용과 할당량 사용량을 줄일 수 있습니다.
종속 작업에는 최대 4개의 종속 항목이 있을 수 있습니다. 각 종속 항목에는 고유한 작업 이름과 다음 필수 상태 중 하나가 포함되어야 합니다.
SUCCEEDED: 성공
FAILED: 실패
FINISHED: 성공 또는 실패
종속 작업을 만들 때는 모든 종속 항목 작업이 있어야 합니다.
종속 작업은 각 종속 작업이 필요한 상태로 전환될 때까지 예약됨 (SCHEDULED) 상태로 전환될 수 없습니다. 종속 작업이 필요한 상태로 전환될 수 없게 되면 종속 작업은 예약되지 않고 즉시 실패합니다.
모든 작업과 마찬가지로 종속 작업은 작업이 대기열의 최대 대기 시간을 초과하는 경우 예약됨 (SCHEDULED) 상태로 전환될 수 없습니다.
Batch는 작업이 오래되지 않도록 이 한도를 적용합니다. 따라서 종속성 작업 중 하나를 완료하는 데 필요한 남은 시간이 이 한도를 초과할 것으로 예상되는 경우 다음 중 하나 이상을 고려하세요.
아직 종속성 작업을 만들지 않은 경우 종속성 작업의 예상 실행 시간을 줄여 보세요. 예를 들어 워크로드의 병렬 처리를 늘리거나 성공할 필요가 없는 작업 및 실행 가능 항목의 실행 시간을 제한할 수 있습니다.
DEPENDENCY_JOB_NAME: 종속 작업의 이름입니다. 이 종속 작업이 예약되려면 종속 작업이 필요한 상태에 도달해야 합니다.
REQUIRED_STATE: 해당 종속 항목 작업의 필수 상태입니다. SUCCEEDED, FAILED 또는 FINISHED여야 합니다.
예를 들어 종속 항목이 3개인 종속 작업에는 다음과 유사한 JSON 구성 파일이 있을 수 있습니다.
{"taskGroups":[{"taskSpec":{"runnables":[{"script":{"text":"echo Hello World! This is task $BATCH_TASK_INDEX."}}]},"taskCount":3}],"dependencies":[{"items":{"DEPENDENCY_JOB_NAME_1":"REQUIRED_STATE_1","DEPENDENCY_JOB_NAME_2":"REQUIRED_STATE_2","DEPENDENCY_JOB_NAME_3":"REQUIRED_STATE_3"}}]}
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-09-05(UTC)"],[[["\u003cp\u003eThis document explains how to create dependent jobs, which are jobs that begin only after specific prior jobs have either succeeded, failed, or finished.\u003c/p\u003e\n"],["\u003cp\u003eUsing dependent jobs helps optimize resource allocation by allowing different VM types to be used for different job phases, such as data preparation versus data processing.\u003c/p\u003e\n"],["\u003cp\u003eDependent jobs have restrictions, such as a maximum of four dependencies, and the required states for dependencies can be \u003ccode\u003eSUCCEEDED\u003c/code\u003e, \u003ccode\u003eFAILED\u003c/code\u003e, or \u003ccode\u003eFINISHED\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eWhen creating a dependent job, all dependency jobs must already exist, and the dependent job won't schedule until each dependency reaches its designated state.\u003c/p\u003e\n"],["\u003cp\u003eYou can create a dependent job using the Google Cloud CLI's \u003ccode\u003egcloud alpha batch jobs submit\u003c/code\u003e command or the Batch API's \u003ccode\u003ev1alpha jobs.create\u003c/code\u003e method, specifying dependencies in the \u003ccode\u003edependencies[].items\u003c/code\u003e field.\u003c/p\u003e\n"]]],[],null,["# Schedule dependent jobs\n\nThis document describes how to create and run a job that isn't scheduled\nuntil specific jobs have succeeded or failed. To learn more about job states,\nsee [Job creation and execution overview](/batch/docs/create-run-job).\n\nIf you have a workload with varying resource requirements, consider using\ndependent jobs to create an automated chain of jobs that each use separate VMs.\nFor example, separate the types of VMs used for low-demand operations\n(like data preparation) and compute-intensive operations (like data processing).\nBy using dependent jobs to help optimize resource consumption, you can reduce\ncosts and quota usage.\n\nBefore you begin\n----------------\n\n1. If you haven't used Batch before, review [Get started with Batch](/batch/docs/get-started) and enable Batch by completing the [prerequisites for projects and users](/batch/docs/get-started#prerequisites).\n2.\n\n To get the permissions that\n you need to create a job,\n\n ask your administrator to grant you the\n following IAM roles:\n\n - [Batch Job Editor](/iam/docs/roles-permissions/batch#batch.jobsEditor) (`roles/batch.jobsEditor`) on the project\n - [Service Account User](/iam/docs/roles-permissions/iam#iam.serviceAccountUser) (`roles/iam.serviceAccountUser`) on the [job's service account](/batch/docs/create-run-job-custom-service-account#create-job-service-account), which by default is the [default Compute Engine service account](/compute/docs/access/service-accounts#default_service_account)\n\n\n For more information about granting roles, see [Manage access to projects, folders, and organizations](/iam/docs/granting-changing-revoking-access).\n\n\n You might also be able to get\n the required permissions through [custom\n roles](/iam/docs/creating-custom-roles) or other [predefined\n roles](/iam/docs/roles-overview#predefined).\n\n\u003cbr /\u003e\n\n### Restrictions\n\nDependent jobs have the following restrictions:\n\n- A dependent job can have up to four dependencies. Each dependency must contain\n a unique job name and one of the following required states:\n\n - `SUCCEEDED`: succeeded\n - `FAILED`: failed\n - `FINISHED`: succeeded or failed\n- When you create a dependent job, all of its dependency jobs must exist.\n\n- A dependent job can't enter the scheduled (`SCHEDULED`) state until each\n dependency job has entered its required state. If it becomes impossible for a\n dependency job to enter its required state, then the dependent job immediately\n fails without being scheduled.\n\n | **Note:** You don't need to wait to delete finished dependency jobs. A dependent job automatically remembers if a deleted dependency job reached its required state.\n- Like all jobs, a dependent job can't enter the scheduled (`SCHEDULED`) state\n if the job exceeds the\n [maximum wait time in the queue](/batch/quotas#max-job-queue).\n Batch enforces this limit to prevent your jobs from becoming\n stale. Consequently, if you expect the remaining time required for any of the\n dependency jobs to finish might exceed this limit, then consider doing one\n or more of the following:\n\n - If you haven't created a dependency job yet, try to reduce the expected run time of the dependency job. For example, you might increase the parallelism of the workload or [limit the run time](/batch/docs/set-timeouts) of any tasks and runnables that you don't need to succeed.\n - Wait to create the dependent job until the expected run time of the dependency jobs is lower than the limit.\n\n### Create a dependent job\n\nYou can [create a job](/batch/docs/create-run-basic-job#create-basic-job) that\nis dependent using the following methods:\n\n- For the Google Cloud CLI, use the [`gcloud alpha batch jobs submit` command](/sdk/gcloud/reference/alpha/batch/jobs/submit).\n- For the Batch API, use the [v1alpha `jobs.create` method](/batch/docs/reference/rest/v1alpha/projects.locations.jobs/create).\n\nTo specify that a job is dependent, include the\n[`dependencies[].items` field](/batch/docs/reference/rest/v1alpha/projects.locations.jobs#Job.FIELDS.dependencies),\nwhich supports one or more dependencies specified as key-value pairs, in the\nmain body in the JSON file: \n\n \"dependencies\": [\n {\n \"items\": {\n \"\u003cvar translate=\"no\"\u003eDEPENDENCY_JOB_NAME\u003c/var\u003e\": \"\u003cvar translate=\"no\"\u003eREQUIRED_STATE\u003c/var\u003e\"\n }\n }\n ]\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003eDEPENDENCY_JOB_NAME\u003c/var\u003e: the name of a dependency job,\n which must reach its required state before this dependent job is allowed to\n be scheduled.\n\n- \u003cvar translate=\"no\"\u003eREQUIRED_STATE\u003c/var\u003e: the required state for the\n corresponding dependency job, which must be `SUCCEEDED`, `FAILED`, or\n `FINISHED`.\n\nFor example, a dependent job with three dependencies can have a JSON\nconfiguration file that is similar to the following: \n\n {\n \"taskGroups\": [\n {\n \"taskSpec\": {\n \"runnables\": [\n {\n \"script\": {\n \"text\": \"echo Hello World! This is task $BATCH_TASK_INDEX.\"\n }\n }\n ]\n },\n \"taskCount\": 3\n }\n ],\n \"dependencies\": [\n {\n \"items\": {\n \"\u003cvar translate=\"no\"\u003eDEPENDENCY_JOB_NAME_1\u003c/var\u003e\": \"\u003cvar translate=\"no\"\u003eREQUIRED_STATE_1\u003c/var\u003e\",\n \"\u003cvar translate=\"no\"\u003eDEPENDENCY_JOB_NAME_2\u003c/var\u003e\": \"\u003cvar translate=\"no\"\u003eREQUIRED_STATE_2\u003c/var\u003e\",\n \"\u003cvar translate=\"no\"\u003eDEPENDENCY_JOB_NAME_3\u003c/var\u003e\": \"\u003cvar translate=\"no\"\u003eREQUIRED_STATE_3\u003c/var\u003e\"\n }\n }\n ]\n }\n\nWhat's next\n-----------\n\n- If you have issues creating or running a job, see [Troubleshooting](/batch/docs/troubleshooting).\n- Learn how to [view jobs and tasks](/batch/docs/view-jobs-tasks).\n- Learn about more [job creation options](/batch/docs/create-run-job#job-creation-options)."]]