์ž‘์—… ๋ฐ ํƒœ์Šคํฌ ๋ณด๊ธฐ

์ด ๋ฌธ์„œ์—์„œ๋Š” ์ผ๊ด„ ์ž‘์—… ๋ฐ ํƒœ์Šคํฌ๋ฅผ ๋ณด๋Š” ๋ฐฉ๋ฒ•์„ ์„ค๋ช…ํ•ฉ๋‹ˆ๋‹ค.

์‹œ์ž‘ํ•˜๊ธฐ ์ „์—

  1. Batch๋ฅผ ์‚ฌ์šฉํ•œ ์ ์ด ์—†์œผ๋ฉด Batch ์‹œ์ž‘ํ•˜๊ธฐ๋ฅผ ๊ฒ€ํ† ํ•˜๊ณ  ํ”„๋กœ์ ํŠธ ๋ฐ ์‚ฌ์šฉ์ž ๊ธฐ๋ณธ ์š”๊ฑด์„ ์™„๋ฃŒํ•˜์—ฌ Batch๋ฅผ ์‚ฌ์šฉ ์„ค์ •ํ•˜์„ธ์š”.
  2. ์ž‘์—… ๋ฐ ํƒœ์Šคํฌ๋ฅผ ๋ณด๋Š” ๋ฐ ํ•„์š”ํ•œ ๊ถŒํ•œ์„ ์–ป์œผ๋ ค๋ฉด ๊ด€๋ฆฌ์ž์—๊ฒŒ ํ”„๋กœ์ ํŠธ์— ๋Œ€ํ•œ Batch ์ž‘์—… ๋ทฐ์–ด (roles/batch.jobsViewer) ๋˜๋Š” Batch ์ž‘์—… ํŽธ์ง‘์ž (roles/batch.jobsEditor) IAM ์—ญํ• ์„ ๋ถ€์—ฌํ•ด ๋‹ฌ๋ผ๊ณ  ์š”์ฒญํ•˜์„ธ์š”. ์—ญํ•  ๋ถ€์—ฌ์— ๋Œ€ํ•œ ์ž์„ธํ•œ ๋‚ด์šฉ์€ ํ”„๋กœ์ ํŠธ, ํด๋”, ์กฐ์ง์— ๋Œ€ํ•œ ์•ก์„ธ์Šค ๊ด€๋ฆฌ๋ฅผ ์ฐธ์กฐํ•˜์„ธ์š”.

    ์ปค์Šคํ…€ ์—ญํ• ์ด๋‚˜ ๋‹ค๋ฅธ ์‚ฌ์ „ ์ •์˜๋œ ์—ญํ• ์„ ํ†ตํ•ด ํ•„์š”ํ•œ ๊ถŒํ•œ์„ ์–ป์„ ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.

์ž‘์—… ๋ณด๊ธฐ

์ž‘์—…์„ ๋ณด๋ ค๋ฉด ๋‹ค์Œ ๋ฐฉ๋ฒ• ์ค‘ ํ•˜๋‚˜๋ฅผ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค.

์ž‘์—… ๋ชฉ๋ก ๋ณด๊ธฐ

Google Cloud ์ฝ˜์†”, gcloud CLI, Batch API, Go, Java, Node.js, Python ๋˜๋Š” C++์„ ์‚ฌ์šฉํ•˜์—ฌ ํ˜„์žฌ ํ”„๋กœ์ ํŠธ์˜ ์ž‘์—… ๋ชฉ๋ก์„ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ฝ˜์†”

  1. Google Cloud ์ฝ˜์†”์„ ์‚ฌ์šฉํ•˜์—ฌ ํ˜„์žฌ ํ”„๋กœ์ ํŠธ์˜ ์ž‘์—… ๋ชฉ๋ก์„ ๋ณด๋ ค๋ฉด ์ž‘์—… ๋ชฉ๋ก ํŽ˜์ด์ง€๋กœ ์ด๋™ํ•ฉ๋‹ˆ๋‹ค.

    ์ž‘์—… ๋ชฉ๋ก์œผ๋กœ ์ด๋™

    ์ž‘์—… ๋ชฉ๋ก์€ ํŽ˜์ด์ง€๊ฐ€ ์—ฌ๋Ÿฌ ๊ฐœ์ผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋‹ค์Œ ํŽ˜์ด์ง€๋กœ ๊ณ„์† ์ง„ํ–‰ํ•ด์•ผ ํ•˜๋Š” ๊ฒฝ์šฐ ํ™”๋ฉด ํ•˜๋‹จ์—์„œ ๋‹ค์Œ์„ ํด๋ฆญํ•˜์„ธ์š”.

  2. (์„ ํƒ์‚ฌํ•ญ) ์ž‘์—… ๋ชฉ๋ก์„ ํ•„ํ„ฐ๋งํ•˜๋ ค๋ฉด ํ•„ํ„ฐ๋ฅผ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋Ÿฐ ๋‹ค์Œ ์†์„ฑ ๋ฐ ๊ฐ’์„ ์ž…๋ ฅํ•˜๊ฑฐ๋‚˜ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค.

    ์˜ˆ๋ฅผ ๋“ค์–ด ํŠน์ • ์ƒํƒœ์˜ ์ž‘์—…๋งŒ ํฌํ•จํ•˜๋„๋ก ๋ชฉ๋ก์„ ํ•„ํ„ฐ๋งํ•˜๋ ค๋ฉด ๋‹ค์Œ์„ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค.

    Status:JOB_STATE
    

    JOB_STATE์„ ์ž‘์—… ์ƒํƒœ๋กœ ๋ฐ”๊ฟ‰๋‹ˆ๋‹ค(์˜ˆ: FAILED).

gcloud

๋ชจ๋“  ์ž‘์—… ๋ณด๊ธฐ

gcloud CLI๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํ˜„์žฌ ํ”„๋กœ์ ํŠธ์˜ ์ž‘์—… ๋ชฉ๋ก์„ ๋ณด๋ ค๋ฉด gcloud batch jobs list ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

gcloud batch jobs list

ํ•„ํ„ฐ๋ง๋œ ์ž‘์—… ๋ชฉ๋ก ๋ณด๊ธฐ

ํ•„์š”ํ•œ ๊ฒฝ์šฐ ํ•˜๋‚˜ ์ด์ƒ์˜ ํ”Œ๋ž˜๊ทธ๋ฅผ ์ถ”๊ฐ€ํ•˜์—ฌ ํ•„ํ„ฐ๋ง๋œ ์ž‘์—… ๋ชฉ๋ก์„ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

  • ํŠน์ • ์œ„์น˜์˜ ์ž‘์—…๋งŒ ๋ณด๋ ค๋ฉด --location ํ”Œ๋ž˜๊ทธ๋ฅผ ํฌํ•จํ•ฉ๋‹ˆ๋‹ค.

  • ํ•„ํ„ฐ ํ‘œํ˜„์‹์„ ๊ธฐ์ค€์œผ๋กœ ์ž‘์—…๋งŒ ๋ณด๋ ค๋ฉด --filter ํ”Œ๋ž˜๊ทธ๋ฅผ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค.

์˜ˆ๋ฅผ ๋“ค์–ด ๋‹ค์Œ ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

gcloud batch jobs list \
    --location=LOCATION \
    --filter="FILTER_EXPRESSION"

๋‹ค์Œ์„ ๋ฐ”๊ฟ‰๋‹ˆ๋‹ค.

  • LOCATION: ํ•˜๋‚˜ ์ด์ƒ์˜ ์ž‘์—…์ด ์žˆ๋Š” ์œ„์น˜

  • FILTER_EXPRESSION: ๋‚˜์—ดํ•  ์ž‘์—…์„ ์ •์˜ํ•˜๋Š” ํ•„ํ„ฐ ํ‘œํ˜„์‹. ํ•„ํ„ฐ ํ‘œํ˜„์‹์€ 0๊ฐœ ์ด์ƒ์˜ ๋ถˆ๋ฆฌ์–ธ ์—ฐ์‚ฐ์ž(AND, OR, NOT)๋กœ ๊ตฌ๋ถ„๋œ ํ•˜๋‚˜ ์ด์ƒ์˜ ์†์„ฑ-๊ฐ’ ์Œ์„ ์ •์˜ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

    ์˜ˆ๋ฅผ ๋“ค์–ด ๋‹ค์Œ ํ•„ํ„ฐ ํ‘œํ˜„์‹์„ ์ฐธ๊ณ ํ•˜์„ธ์š”.

    • ์ž‘์—… ์ƒํƒœ ๊ธฐ๋ฐ˜ ํ•„ํ„ฐ๋ง: ํŠน์ • ์ƒํƒœ์˜ ์ž‘์—…๋งŒ ํ‘œ์‹œํ•˜๋ ค๋ฉด ๋‹ค์Œ ํ•„ํ„ฐ ํ‘œํ˜„์‹์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

      status.state="JOB_STATE"
      

      JOB_STATE์„ ์ž‘์—… ์ƒํƒœ๋กœ ๋ฐ”๊ฟ‰๋‹ˆ๋‹ค(์˜ˆ: FAILED).

    • ๋ผ๋ฒจ ๊ธฐ๋ฐ˜ ํ•„ํ„ฐ๋ง: ํ”„๋กœ์ ํŠธ์—์„œ ๋‹ค์Œ ์ปค์Šคํ…€ ๋ผ๋ฒจ์„ ์ •์˜ํ–ˆ๋‹ค๊ณ  ๊ฐ€์ •ํ•ฉ๋‹ˆ๋‹ค.

      • Cloud Billing ๋ณด๊ณ ์„œ๋ฅผ ๋ณผ ๋•Œ ๋ฆฌ์„œ์น˜ํŒ€์—์„œ ๋งŒ๋“  ์ž‘์—…๊ณผ ํ•ด๋‹น ๋ฆฌ์†Œ์Šค๋ฅผ ํ‘œ์‹œํ•˜๊ธฐ ์œ„ํ•ด ์ผ๋ถ€ ์ž‘์—… ๋ฐ ํ•ด๋‹น ๋ฆฌ์†Œ์Šค์—๋Š” research๋กœ ์„ค์ •๋œ team ๋ผ๋ฒจ์ด ์žˆ์Šต๋‹ˆ๋‹ค.

      • ์‹œ๊ฐ„์— ๋ฏผ๊ฐํ•œ ์›Œํฌ๋กœ๋“œ๋ฅผ ํ‘œ์‹œํ•˜๊ธฐ ์œ„ํ•ด ์ผ๋ถ€ ์ž‘์—…์—๋Š” ๋‹ค์–‘ํ•œ ๊ฐ’์œผ๋กœ ์„ค์ •๋œ deadline ๋ผ๋ฒจ์ด ์žˆ์Šต๋‹ˆ๋‹ค.

      • ๊ฐœ๋ฐœํŒ€์ด ์„ฑ๊ณต์ ์œผ๋กœ ํ…Œ์ŠคํŠธํ•œ ์‹คํ–‰ ๊ฐ€๋Šฅ ํ•ญ๋ชฉ์„ ๋‚˜ํƒ€๋‚ด๊ธฐ ์œ„ํ•ด ์ผ๋ถ€ ์‹คํ–‰ ๊ฐ€๋Šฅ ํ•ญ๋ชฉ์—๋Š” true๋กœ ์„ค์ •๋œ tested ๋ผ๋ฒจ์ด ์žˆ์Šต๋‹ˆ๋‹ค.

      ๊ทธ๋Ÿฐ ๋‹ค์Œ, ๋‹ค์Œ ํ•„ํ„ฐ ํ‘œํ˜„์‹์„ ์ง€์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

      (allocationPolicy.labels.team=research) AND ((labels.deadline:*) OR (runnables.labels.tested=true))
      

      ์ด ํ•„ํ„ฐ ํ‘œํ˜„์‹์€ ๋‹ค์Œ ๊ธฐ์ค€์„ ๋ชจ๋‘ ์ถฉ์กฑํ•˜๋Š” ์ž‘์—…๋งŒ ๋‚˜์—ดํ•ฉ๋‹ˆ๋‹ค.

      • research๋กœ ์„ค์ •๋œ ์ž‘์—… ํ• ๋‹น ์ •์ฑ…์— team ๋ผ๋ฒจ์ด ์žˆ๋Š” ๋ฆฌ์„œ์น˜ํŒ€์˜ ์ž‘์—…์ž…๋‹ˆ๋‹ค.

      • ๋‹ค์Œ ๊ธฐ์ค€ ์ค‘ ํ•˜๋‚˜ ์ด์ƒ์„ ์ถฉ์กฑํ•˜๋Š” ์ž‘์—…:

        • ์ž„์˜์˜ ๊ฐ’์œผ๋กœ ์„ค์ •๋œ ์ž‘์—…์— deadline ๋ผ๋ฒจ์ด ์žˆ๋Š” ์‹œ๊ฐ„์— ๋ฏผ๊ฐํ•œ ์ž‘์—…

        • ์„ฑ๊ณต์ ์œผ๋กœ ํ…Œ์ŠคํŠธ๋œ ์‹คํ–‰ ๊ฐ€๋Šฅํ•œ ํ•ญ๋ชฉ์ด ํ•˜๋‚˜ ์ด์ƒ ์žˆ๋Š” ์ž‘์—…, ์ฆ‰ true๋กœ ์„ค์ •๋œ tested ๋ผ๋ฒจ์„ ์‚ฌ์šฉํ•œ ์‹คํ–‰ ๊ฐ€๋Šฅํ•œ ํ•ญ๋ชฉ์ด ํ•˜๋‚˜ ์ด์ƒ ์žˆ๋Š” ์ž‘์—…

API

๋ชจ๋“  ์ž‘์—… ๋ณด๊ธฐ

Batch API๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํŠน์ • ์œ„์น˜์˜ ํ˜„์žฌ ํ”„๋กœ์ ํŠธ์— ์žˆ๋Š” ์ž‘์—… ๋ชฉ๋ก์„ ๋ณด๋ ค๋ฉด jobs.list ๋ฉ”์„œ๋“œ์— ๋Œ€ํ•ด GET ์š”์ฒญ์„ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

GET https://batch.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/jobs

๋‹ค์Œ์„ ๋ฐ”๊ฟ‰๋‹ˆ๋‹ค.

ํ•„ํ„ฐ๋ง๋œ ์ž‘์—… ๋ชฉ๋ก ๋ณด๊ธฐ

ํ•„์š”ํ•œ ๊ฒฝ์šฐ ํ•„ํ„ฐ ํ‘œํ˜„์‹์— ๋”ฐ๋ผ ํ•„ํ„ฐ๋ง๋œ ์ž‘์—… ๋ชฉ๋ก์„ ๋ณด๊ธฐ ์œ„ํ•ด filter ์ฟผ๋ฆฌ ๋งค๊ฐœ๋ณ€์ˆ˜๋ฅผ ์ง€์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์˜ˆ๋ฅผ ๋“ค์–ด ๋‹ค์Œ GET ์š”์ฒญ์„ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค.

GET https://batch.googleapis.com/v1/projects/example-project/locations/us-central1/jobs?filter=FILTER_EXPRESSION

FILTER_EXPRESSION์„ URL ์ธ์ฝ”๋”ฉ์„ ์‚ฌ์šฉํ•˜๋Š” ํ•„ํ„ฐ ํ‘œํ˜„์‹์œผ๋กœ ๋ฐ”๊ฟ‰๋‹ˆ๋‹ค. ํ•„ํ„ฐ ํ‘œํ˜„์‹์€ 0๊ฐœ ์ด์ƒ์˜ ๋ถˆ๋ฆฌ์–ธ ์—ฐ์‚ฐ์ž(AND, OR, NOT)๋กœ ๊ตฌ๋ถ„๋œ ํ•˜๋‚˜ ์ด์ƒ์˜ ์†์„ฑ-๊ฐ’ ์Œ์„ ์ •์˜ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

์˜ˆ๋ฅผ ๋“ค์–ด ๋‹ค์Œ ํ•„ํ„ฐ ํ‘œํ˜„์‹์„ ์ฐธ๊ณ ํ•˜์„ธ์š”.

  • ์ž‘์—… ์ƒํƒœ ๊ธฐ๋ฐ˜ ํ•„ํ„ฐ๋ง: ํŠน์ • ์ƒํƒœ์˜ ์ž‘์—…๋งŒ ํ‘œ์‹œํ•˜๋ ค๋ฉด ๋‹ค์Œ ํ•„ํ„ฐ ํ‘œํ˜„์‹์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

    status.state="JOB_STATE"
    

    JOB_STATE์„ ์ž‘์—… ์ƒํƒœ๋กœ ๋ฐ”๊ฟ‰๋‹ˆ๋‹ค(์˜ˆ: FAILED).

  • ๋ผ๋ฒจ ๊ธฐ๋ฐ˜ ํ•„ํ„ฐ๋ง: ํ”„๋กœ์ ํŠธ์—์„œ ๋‹ค์Œ ์ปค์Šคํ…€ ๋ผ๋ฒจ์„ ์ •์˜ํ–ˆ๋‹ค๊ณ  ๊ฐ€์ •ํ•ฉ๋‹ˆ๋‹ค.

    • Cloud Billing ๋ณด๊ณ ์„œ๋ฅผ ๋ณผ ๋•Œ ๋ฆฌ์„œ์น˜ํŒ€์—์„œ ๋งŒ๋“  ์ž‘์—…๊ณผ ํ•ด๋‹น ๋ฆฌ์†Œ์Šค๋ฅผ ํ‘œ์‹œํ•˜๊ธฐ ์œ„ํ•ด ์ผ๋ถ€ ์ž‘์—… ๋ฐ ํ•ด๋‹น ๋ฆฌ์†Œ์Šค์—๋Š” research๋กœ ์„ค์ •๋œ team ๋ผ๋ฒจ์ด ์žˆ์Šต๋‹ˆ๋‹ค.

    • ์‹œ๊ฐ„์— ๋ฏผ๊ฐํ•œ ์›Œํฌ๋กœ๋“œ๋ฅผ ํ‘œ์‹œํ•˜๊ธฐ ์œ„ํ•ด ์ผ๋ถ€ ์ž‘์—…์—๋Š” ๋‹ค์–‘ํ•œ ๊ฐ’์œผ๋กœ ์„ค์ •๋œ deadline ๋ผ๋ฒจ์ด ์žˆ์Šต๋‹ˆ๋‹ค.

    • ๊ฐœ๋ฐœํŒ€์ด ์„ฑ๊ณต์ ์œผ๋กœ ํ…Œ์ŠคํŠธํ•œ ์‹คํ–‰ ๊ฐ€๋Šฅ ํ•ญ๋ชฉ์„ ๋‚˜ํƒ€๋‚ด๊ธฐ ์œ„ํ•ด ์ผ๋ถ€ ์‹คํ–‰ ๊ฐ€๋Šฅ ํ•ญ๋ชฉ์—๋Š” true๋กœ ์„ค์ •๋œ tested ๋ผ๋ฒจ์ด ์žˆ์Šต๋‹ˆ๋‹ค.

    ๊ทธ๋Ÿฐ ๋‹ค์Œ, ๋‹ค์Œ ํ•„ํ„ฐ ํ‘œํ˜„์‹์„ ์ง€์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

    (allocationPolicy.labels.team%3Dresearch)%20AND%20((labels.deadline%3A*)%20OR%20(runnables.labels.tested%3Dtrue))
    

    ์ด ํ•„ํ„ฐ ํ‘œํ˜„์‹์€ ๋‹ค์Œ ๊ธฐ์ค€์„ ๋ชจ๋‘ ์ถฉ์กฑํ•˜๋Š” ์ž‘์—…๋งŒ ๋‚˜์—ดํ•ฉ๋‹ˆ๋‹ค.

    • research๋กœ ์„ค์ •๋œ ์ž‘์—… ํ• ๋‹น ์ •์ฑ…์— team ๋ผ๋ฒจ์ด ์žˆ๋Š” ๋ฆฌ์„œ์น˜ํŒ€์˜ ์ž‘์—…์ž…๋‹ˆ๋‹ค.

    • ๋‹ค์Œ ๊ธฐ์ค€ ์ค‘ ํ•˜๋‚˜ ์ด์ƒ์„ ์ถฉ์กฑํ•˜๋Š” ์ž‘์—…:

      • ์ž„์˜์˜ ๊ฐ’์œผ๋กœ ์„ค์ •๋œ ์ž‘์—…์— deadline ๋ผ๋ฒจ์ด ์žˆ๋Š” ์‹œ๊ฐ„์— ๋ฏผ๊ฐํ•œ ์ž‘์—…

      • ์„ฑ๊ณต์ ์œผ๋กœ ํ…Œ์ŠคํŠธ๋œ ์‹คํ–‰ ๊ฐ€๋Šฅํ•œ ํ•ญ๋ชฉ์ด ํ•˜๋‚˜ ์ด์ƒ ์žˆ๋Š” ์ž‘์—…, ์ฆ‰ true๋กœ ์„ค์ •๋œ tested ๋ผ๋ฒจ์„ ์‚ฌ์šฉํ•œ ์‹คํ–‰ ๊ฐ€๋Šฅํ•œ ํ•ญ๋ชฉ์ด ํ•˜๋‚˜ ์ด์ƒ ์žˆ๋Š” ์ž‘์—…

Go

Go

์ž์„ธํ•œ ๋‚ด์šฉ์€ Batch Go API ์ฐธ๊ณ  ๋ฌธ์„œ๋ฅผ ํ™•์ธํ•˜์„ธ์š”.

Batch์— ์ธ์ฆํ•˜๋ ค๋ฉด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ธฐ๋ณธ ์‚ฌ์šฉ์ž ์ธ์ฆ ์ •๋ณด๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. ์ž์„ธํ•œ ๋‚ด์šฉ์€ ๋กœ์ปฌ ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์˜ ์ธ์ฆ ์„ค์ •์„ ์ฐธ์กฐํ•˜์„ธ์š”.

import (
	"context"
	"fmt"
	"io"

	batch "cloud.google.com/go/batch/apiv1"
	"cloud.google.com/go/batch/apiv1/batchpb"
	"google.golang.org/api/iterator"
)

// Lists all jobs in the given project and region
func listJobs(w io.Writer, projectID, region string) error {
	// projectID := "your_project_id"
	// region := "us-central1"

	ctx := context.Background()
	batchClient, err := batch.NewClient(ctx)
	if err != nil {
		return fmt.Errorf("NewClient: %w", err)
	}
	defer batchClient.Close()

	req := &batchpb.ListJobsRequest{
		Parent: fmt.Sprintf("projects/%s/locations/%s", projectID, region),
	}

	var jobs []*batchpb.Job
	it := batchClient.ListJobs(ctx, req)

	for {
		job, err := it.Next()
		if err == iterator.Done {
			break
		}
		if err != nil {
			return fmt.Errorf("unable to list jobs: %w", err)
		}
		jobs = append(jobs, job)
	}

	fmt.Fprintf(w, "Jobs: %v\n", jobs)

	return nil
}

์ž๋ฐ”

Java

์ž์„ธํ•œ ๋‚ด์šฉ์€ Batch Java API ์ฐธ๊ณ  ๋ฌธ์„œ๋ฅผ ํ™•์ธํ•˜์„ธ์š”.

Batch์— ์ธ์ฆํ•˜๋ ค๋ฉด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ธฐ๋ณธ ์‚ฌ์šฉ์ž ์ธ์ฆ ์ •๋ณด๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. ์ž์„ธํ•œ ๋‚ด์šฉ์€ ๋กœ์ปฌ ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์˜ ์ธ์ฆ ์„ค์ •์„ ์ฐธ์กฐํ•˜์„ธ์š”.

import com.google.cloud.batch.v1.BatchServiceClient;
import com.google.cloud.batch.v1.Job;
import java.io.IOException;

public class ListJobs {

  public static void main(String[] args) throws IOException {
    // TODO(developer): Replace these variables before running the sample.
    // Project ID or project number of the Cloud project you want to use.
    String projectId = "YOUR_PROJECT_ID";

    // Name of the region hosting the jobs.
    String region = "europe-central2";

    listJobs(projectId, region);
  }

  // Get a list of all jobs defined in given region.
  public static void listJobs(String projectId, String region) throws IOException {
    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the `batchServiceClient.close()` method on the client to safely
    // clean up any remaining background resources.
    try (BatchServiceClient batchServiceClient = BatchServiceClient.create()) {

      // Construct the parent path of the job.
      String parent = String.format("projects/%s/locations/%s", projectId, region);

      for (Job job : batchServiceClient.listJobs(parent).iterateAll()) {
        System.out.println(job.getName());
      }
      System.out.println("Listed all batch jobs.");
    }
  }
}

Node.js

Node.js

์ž์„ธํ•œ ๋‚ด์šฉ์€ Batch Node.js API ์ฐธ๊ณ  ๋ฌธ์„œ๋ฅผ ํ™•์ธํ•˜์„ธ์š”.

Batch์— ์ธ์ฆํ•˜๋ ค๋ฉด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ธฐ๋ณธ ์‚ฌ์šฉ์ž ์ธ์ฆ ์ •๋ณด๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. ์ž์„ธํ•œ ๋‚ด์šฉ์€ ๋กœ์ปฌ ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์˜ ์ธ์ฆ ์„ค์ •์„ ์ฐธ์กฐํ•˜์„ธ์š”.

/**
 * TODO(developer): Uncomment and replace these variables before running the sample.
 */
// const projectId = 'YOUR_PROJECT_ID';
/**
 * The region that hosts the job.
 */
// const region = 'us-central-1';

// Imports the Batch library
const batchLib = require('@google-cloud/batch');

// Instantiates a client
const batchClient = new batchLib.v1.BatchServiceClient();

async function callListJobs() {
  // Construct request
  const request = {
    parent: `projects/${projectId}/locations/${region}`,
  };

  // Run request
  const iterable = await batchClient.listJobsAsync(request);
  for await (const response of iterable) {
    console.log(response);
  }
}

await callListJobs();

Python

Python

์ž์„ธํ•œ ๋‚ด์šฉ์€ Batch Python API ์ฐธ๊ณ  ๋ฌธ์„œ๋ฅผ ํ™•์ธํ•˜์„ธ์š”.

Batch์— ์ธ์ฆํ•˜๋ ค๋ฉด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ธฐ๋ณธ ์‚ฌ์šฉ์ž ์ธ์ฆ ์ •๋ณด๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. ์ž์„ธํ•œ ๋‚ด์šฉ์€ ๋กœ์ปฌ ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์˜ ์ธ์ฆ ์„ค์ •์„ ์ฐธ์กฐํ•˜์„ธ์š”.

from __future__ import annotations

from collections.abc import Iterable

from google.cloud import batch_v1


def list_jobs(project_id: str, region: str) -> Iterable[batch_v1.Job]:
    """
    Get a list of all jobs defined in given region.

    Args:
        project_id: project ID or project number of the Cloud project you want to use.
        region: name of the region hosting the jobs.

    Returns:
        An iterable collection of Job object.
    """
    client = batch_v1.BatchServiceClient()

    return client.list_jobs(parent=f"projects/{project_id}/locations/{region}")

C++

C++

์ž์„ธํ•œ ๋‚ด์šฉ์€ Batch C++ API ์ฐธ๊ณ  ๋ฌธ์„œ๋ฅผ ํ™•์ธํ•˜์„ธ์š”.

Batch์— ์ธ์ฆํ•˜๋ ค๋ฉด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ธฐ๋ณธ ์‚ฌ์šฉ์ž ์ธ์ฆ ์ •๋ณด๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. ์ž์„ธํ•œ ๋‚ด์šฉ์€ ๋กœ์ปฌ ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์˜ ์ธ์ฆ ์„ค์ •์„ ์ฐธ์กฐํ•˜์„ธ์š”.

#include "google/cloud/batch/v1/batch_client.h"

  [](std::string const& project_id, std::string const& location_id) {
    auto const parent = "projects/" + project_id + "/locations/" + location_id;
    // Initialize a client and issue the request.
    auto client = google::cloud::batch_v1::BatchServiceClient(
        google::cloud::batch_v1::MakeBatchServiceConnection());
    int i = 0;
    for (auto job : client.ListJobs(parent)) {
      if (!job) throw std::move(job).status();
      std::cout << "Job[" << i++ << "]  " << job->DebugString() << "\n";
    }
  }

์ž‘์—… ์„ธ๋ถ€์ •๋ณด ๋ณด๊ธฐ

Google Cloud ์ฝ˜์†”, gcloud CLI, Batch API, Go, Java, Node.js, Python ๋˜๋Š” C++์„ ์‚ฌ์šฉํ•˜์—ฌ ํ˜„์žฌ ํ”„๋กœ์ ํŠธ์˜ ์ž‘์—… ์„ธ๋ถ€์ •๋ณด๋ฅผ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ฝ˜์†”

Google Cloud ์ฝ˜์†”์„ ์‚ฌ์šฉํ•˜์—ฌ ํ˜„์žฌ ํ”„๋กœ์ ํŠธ์˜ ์ž‘์—… ์„ธ๋ถ€์ •๋ณด๋ฅผ ๋ณด๋ ค๋ฉด ๋‹ค์Œ ๋‹จ๊ณ„๋ฅผ ๋”ฐ๋ฅด์„ธ์š”.

  1. Google Cloud ์ฝ˜์†”์—์„œ ์ž‘์—… ๋ชฉ๋ก ํŽ˜์ด์ง€๋กœ ์ด๋™ํ•ฉ๋‹ˆ๋‹ค.

    ์ž‘์—… ๋ชฉ๋ก์œผ๋กœ ์ด๋™

  2. ์ž‘์—… ์ด๋ฆ„ ์—ด์—์„œ ์ž‘์—… ์ด๋ฆ„์„ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค.

    ์ž‘์—… ์„ธ๋ถ€์ •๋ณด ํŽ˜์ด์ง€๊ฐ€ ์—ด๋ฆฝ๋‹ˆ๋‹ค.

    ์„ธ๋ถ€์ •๋ณด ํƒญ์ด ๊ธฐ๋ณธ์ ์œผ๋กœ ์—ด๋ฆฝ๋‹ˆ๋‹ค. ์ž์„ธํ•œ ๋‚ด์šฉ์„ ๋ณด๋ ค๋ฉด ๋‹ค๋ฅธ ํƒญ์„ ํด๋ฆญํ•˜์„ธ์š”.

gcloud

gcloud CLI๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํ˜„์žฌ ํ”„๋กœ์ ํŠธ์˜ ์ž‘์—… ์„ธ๋ถ€์ •๋ณด๋ฅผ ๋ณด๋ ค๋ฉด --location ํ”Œ๋ž˜๊ทธ์™€ ํ•จ๊ป˜ gcloud batch jobs describe ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

gcloud batch jobs describe JOB_NAME \
    --location=LOCATION

๋‹ค์Œ์„ ๋ฐ”๊ฟ‰๋‹ˆ๋‹ค.

  • JOB_NAME: ๊ธฐ์กด ์ž‘์—…์˜ ์ด๋ฆ„์ž…๋‹ˆ๋‹ค.

  • LOCATION: ์ž‘์—…์ด ์žˆ๋Š” ์œ„์น˜์ž…๋‹ˆ๋‹ค.

API

Batch API๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํ˜„์žฌ ํ”„๋กœ์ ํŠธ์˜ ์ž‘์—… ์„ธ๋ถ€์ •๋ณด๋ฅผ ๋ณด๋ ค๋ฉด jobs.get ๋ฉ”์„œ๋“œ์— GET ์š”์ฒญ์„ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค.

GET https://batch.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/jobs/JOB_NAME

๋‹ค์Œ์„ ๋ฐ”๊ฟ‰๋‹ˆ๋‹ค.

  • PROJECT_ID: ํ˜„์žฌ ํ”„๋กœ์ ํŠธ์˜ ํ”„๋กœ์ ํŠธ ID์ž…๋‹ˆ๋‹ค.

  • LOCATION: ์ž‘์—…์ด ์žˆ๋Š” ์œ„์น˜์ž…๋‹ˆ๋‹ค.

  • JOB_NAME: ๊ธฐ์กด ์ž‘์—…์˜ ์ด๋ฆ„์ž…๋‹ˆ๋‹ค.

Go

Go

์ž์„ธํ•œ ๋‚ด์šฉ์€ Batch Go API ์ฐธ๊ณ  ๋ฌธ์„œ๋ฅผ ํ™•์ธํ•˜์„ธ์š”.

Batch์— ์ธ์ฆํ•˜๋ ค๋ฉด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ธฐ๋ณธ ์‚ฌ์šฉ์ž ์ธ์ฆ ์ •๋ณด๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. ์ž์„ธํ•œ ๋‚ด์šฉ์€ ๋กœ์ปฌ ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์˜ ์ธ์ฆ ์„ค์ •์„ ์ฐธ์กฐํ•˜์„ธ์š”.

import (
	"context"
	"fmt"
	"io"

	batch "cloud.google.com/go/batch/apiv1"
	"cloud.google.com/go/batch/apiv1/batchpb"
)

// Retrieves the information about the specified job, most importantly its status
func getJob(w io.Writer, projectID, region, jobName string) (*batchpb.Job, error) {
	// projectID := "your_project_id"
	// region := "us-central1"
	// jobName := "some-job"

	ctx := context.Background()
	batchClient, err := batch.NewClient(ctx)
	if err != nil {
		return nil, fmt.Errorf("NewClient: %w", err)
	}
	defer batchClient.Close()

	req := &batchpb.GetJobRequest{
		Name: fmt.Sprintf("projects/%s/locations/%s/jobs/%s", projectID, region, jobName),
	}

	response, err := batchClient.GetJob(ctx, req)
	if err != nil {
		return nil, fmt.Errorf("unable to get job: %w", err)
	}

	fmt.Fprintf(w, "Job info: %v\n", response)

	return response, nil
}

์ž๋ฐ”

Java

์ž์„ธํ•œ ๋‚ด์šฉ์€ Batch Java API ์ฐธ๊ณ  ๋ฌธ์„œ๋ฅผ ํ™•์ธํ•˜์„ธ์š”.

Batch์— ์ธ์ฆํ•˜๋ ค๋ฉด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ธฐ๋ณธ ์‚ฌ์šฉ์ž ์ธ์ฆ ์ •๋ณด๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. ์ž์„ธํ•œ ๋‚ด์šฉ์€ ๋กœ์ปฌ ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์˜ ์ธ์ฆ ์„ค์ •์„ ์ฐธ์กฐํ•˜์„ธ์š”.

import com.google.cloud.batch.v1.BatchServiceClient;
import com.google.cloud.batch.v1.Job;
import com.google.cloud.batch.v1.JobName;
import java.io.IOException;

public class GetJob {

  public static void main(String[] args) throws IOException {
    // TODO(developer): Replace these variables before running the sample.
    // Project ID or project number of the Cloud project you want to use.
    String projectId = "YOUR_PROJECT_ID";

    // Name of the region hosts the job.
    String region = "europe-central2";

    // The name of the job you want to retrieve information about.
    String jobName = "JOB_NAME";

    getJob(projectId, region, jobName);
  }

  // Retrieve information about a Batch Job.
  public static void getJob(String projectId, String region, String jobName) throws IOException {
    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the `batchServiceClient.close()` method on the client to safely
    // clean up any remaining background resources.
    try (BatchServiceClient batchServiceClient = BatchServiceClient.create()) {

      Job job =
          batchServiceClient.getJob(
              JobName.newBuilder()
                  .setProject(projectId)
                  .setLocation(region)
                  .setJob(jobName)
                  .build());

      System.out.printf("Retrieved the job: %s ", job.getName());
    }
  }
}

Node.js

Node.js

์ž์„ธํ•œ ๋‚ด์šฉ์€ Batch Node.js API ์ฐธ๊ณ  ๋ฌธ์„œ๋ฅผ ํ™•์ธํ•˜์„ธ์š”.

Batch์— ์ธ์ฆํ•˜๋ ค๋ฉด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ธฐ๋ณธ ์‚ฌ์šฉ์ž ์ธ์ฆ ์ •๋ณด๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. ์ž์„ธํ•œ ๋‚ด์šฉ์€ ๋กœ์ปฌ ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์˜ ์ธ์ฆ ์„ค์ •์„ ์ฐธ์กฐํ•˜์„ธ์š”.

/**
 * TODO(developer): Uncomment and replace these variables before running the sample.
 */
// const projectId = 'YOUR_PROJECT_ID';
/**
 * The region that hosts the job.
 */
// const region = 'us-central-1';
/**
 * The name of the job you want to retrieve information about.
 */
// const jobName = 'YOUR_JOB_NAME';

// Imports the Batch library
const batchLib = require('@google-cloud/batch');

// Instantiates a client
const batchClient = new batchLib.v1.BatchServiceClient();

async function callGetJob() {
  // Construct request
  const request = {
    name: `projects/${projectId}/locations/${region}/jobs/${jobName}`,
  };

  // Run request
  const response = await batchClient.getJob(request);
  console.log(response);
}

await callGetJob();

Python

Python

์ž์„ธํ•œ ๋‚ด์šฉ์€ Batch Python API ์ฐธ๊ณ  ๋ฌธ์„œ๋ฅผ ํ™•์ธํ•˜์„ธ์š”.

Batch์— ์ธ์ฆํ•˜๋ ค๋ฉด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ธฐ๋ณธ ์‚ฌ์šฉ์ž ์ธ์ฆ ์ •๋ณด๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. ์ž์„ธํ•œ ๋‚ด์šฉ์€ ๋กœ์ปฌ ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์˜ ์ธ์ฆ ์„ค์ •์„ ์ฐธ์กฐํ•˜์„ธ์š”.


from google.cloud import batch_v1


def get_job(project_id: str, region: str, job_name: str) -> batch_v1.Job:
    """
    Retrieve information about a Batch Job.

    Args:
        project_id: project ID or project number of the Cloud project you want to use.
        region: name of the region hosts the job.
        job_name: the name of the job you want to retrieve information about.

    Returns:
        A Job object representing the specified job.
    """
    client = batch_v1.BatchServiceClient()

    return client.get_job(
        name=f"projects/{project_id}/locations/{region}/jobs/{job_name}"
    )

C++

C++

์ž์„ธํ•œ ๋‚ด์šฉ์€ Batch C++ API ์ฐธ๊ณ  ๋ฌธ์„œ๋ฅผ ํ™•์ธํ•˜์„ธ์š”.

Batch์— ์ธ์ฆํ•˜๋ ค๋ฉด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ธฐ๋ณธ ์‚ฌ์šฉ์ž ์ธ์ฆ ์ •๋ณด๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. ์ž์„ธํ•œ ๋‚ด์šฉ์€ ๋กœ์ปฌ ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์˜ ์ธ์ฆ ์„ค์ •์„ ์ฐธ์กฐํ•˜์„ธ์š”.

#include "google/cloud/batch/v1/batch_client.h"

  [](std::string const& project_id, std::string const& location_id,
     std::string const& job_id) {
    auto const name = "projects/" + project_id + "/locations/" + location_id +
                      "/jobs/" + job_id;
    // Initialize a client and issue the request.
    auto client = google::cloud::batch_v1::BatchServiceClient(
        google::cloud::batch_v1::MakeBatchServiceConnection());
    auto response = client.GetJob(name);
    if (!response) throw std::move(response).status();
    std::cout << "GetJob() succeeded with " << response->DebugString() << "\n";
  }

ํ•  ์ผ ๋ณด๊ธฐ

์ž‘์—… ์ค‘ ํ•˜๋‚˜์˜ ํƒœ์Šคํฌ๋ฅผ ๋ณด๋ ค๋ฉด ๋‹ค์Œ ๋ฐฉ๋ฒ• ์ค‘ ํ•˜๋‚˜๋ฅผ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค.

์ž‘์—… ํƒœ์Šคํฌ ๋ชฉ๋ก ๋ณด๊ธฐ

Google Cloud ์ฝ˜์†”, gcloud CLI, Batch API, Go, Java, Node.js, Python ๋˜๋Š” C++์„ ์‚ฌ์šฉํ•˜์—ฌ ์ž‘์—… ๋˜๋Š” ์ž‘์—…์˜ ํƒœ์Šคํฌ ๊ทธ๋ฃน์—์„œ ํƒœ์Šคํฌ ๋ชฉ๋ก์„ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ž‘์—… ๋˜๋Š” ์ž‘์—…์˜ ํƒœ์Šคํฌ ๊ทธ๋ฃน์— ์žˆ๋Š” ํƒœ์Šคํฌ ๋ชฉ๋ก์„ ํ•„ํ„ฐ๋งํ•˜๋ ค๋ฉด(์˜ˆ: ์‹คํ–‰์ด ์™„๋ฃŒ๋œ ์ž‘์—…๋งŒ ๋‚˜์—ด) gcloud CLI ๋˜๋Š” Batch API๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

์ฝ˜์†”

Google Cloud ์ฝ˜์†”์„ ์‚ฌ์šฉํ•˜์—ฌ ์ž‘์—…์˜ ํƒœ์Šคํฌ ์š”์•ฝ์„ ๋ณด๋ ค๋ฉด ์ž‘์—… ์„ธ๋ถ€์ •๋ณด๋ฅผ ํ™•์ธํ•˜์—ฌ ์ž‘์—… ์„ธ๋ถ€์ •๋ณด ํŽ˜์ด์ง€๋ฅผ ์—ฝ๋‹ˆ๋‹ค. ๊ทธ๋Ÿฐ ๋‹ค์Œ ํƒœ์Šคํฌ ์„ธ๋ถ€์ •๋ณด ์„น์…˜์„ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.

gcloud

gcloud CLI๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ž‘์—… ํƒœ์Šคํฌ ๊ทธ๋ฃน์˜ ํƒœ์Šคํฌ ๋ชฉ๋ก์„ ๋ณด๋ ค๋ฉด ๋‹ค์Œ ํ”Œ๋ž˜๊ทธ์™€ ํ•จ๊ป˜ gcloud batch tasks list ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

gcloud batch tasks list \
    --job=JOB_NAME \
    --location=LOCATION

๋‹ค์Œ์„ ๋ฐ”๊ฟ‰๋‹ˆ๋‹ค.

  • JOB_NAME: ๊ธฐ์กด ์ž‘์—…์˜ ์ด๋ฆ„์ž…๋‹ˆ๋‹ค.

  • LOCATION: ์ž‘์—…์ด ์žˆ๋Š” ์œ„์น˜์ž…๋‹ˆ๋‹ค.

์›ํ•˜๋Š” ๊ฒฝ์šฐ --filter ํ”Œ๋ž˜๊ทธ๋ฅผ ์ถ”๊ฐ€ํ•˜์—ฌ ํ•„ํ„ฐ ํ‘œํ˜„์‹์„ ๊ธฐ์ค€์œผ๋กœ ์ž‘์—…์˜ ํƒœ์Šคํฌ ๊ทธ๋ฃน์— ์žˆ๋Š” ํ•„ํ„ฐ๋ง๋œ ํƒœ์Šคํฌ ๋ชฉ๋ก์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์˜ˆ๋ฅผ ๋“ค์–ด ๋‹ค์Œ ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

gcloud batch tasks list \
    --job=example-job \
    --location=us-central1 \
    --filter="FILTER_EXPRESSION"

FILTER_EXPRESSION์„ ํ•„ํ„ฐ ํ‘œํ˜„์‹์œผ๋กœ ๋ฐ”๊ฟ‰๋‹ˆ๋‹ค.

์˜ˆ๋ฅผ ๋“ค์–ด ์‹คํ–‰ ์ค‘์ด๊ฑฐ๋‚˜ ์‹คํ–‰์„ ์„ฑ๊ณต์ ์œผ๋กœ ๋งˆ์นœ ์ž‘์—…์˜ ํƒœ์Šคํฌ ๊ทธ๋ฃน์— ์žˆ๋Š” ํƒœ์Šคํฌ๋งŒ ํ‘œ์‹œํ•˜๋„๋ก ๋‹ค์Œ ํ•„ํ„ฐ ํ‘œํ˜„์‹์„ ์ง€์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

STATE=RUNNING OR STATE=SUCCEEDED

API

Batch API๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ž‘์—…์˜ ํƒœ์Šคํฌ ๊ทธ๋ฃน์— ์žˆ๋Š” ํƒœ์Šคํฌ ๋ชฉ๋ก์„ ๋ณด๋ ค๋ฉด tasks.list ๋ฉ”์„œ๋“œ์— ๋Œ€ํ•œGET ์š”์ฒญ์„ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค.

GET https://batch.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/jobs/JOB_NAME/taskGroups/TASK_GROUP_NAME/tasks

๋‹ค์Œ์„ ๋ฐ”๊ฟ‰๋‹ˆ๋‹ค.

  • PROJECT_ID: ํ˜„์žฌ ํ”„๋กœ์ ํŠธ์˜ ํ”„๋กœ์ ํŠธ ID์ž…๋‹ˆ๋‹ค.

  • LOCATION: ์ž‘์—…์ด ์žˆ๋Š” ์œ„์น˜์ž…๋‹ˆ๋‹ค.

  • JOB_NAME: ๊ธฐ์กด ์ž‘์—…์˜ ์ด๋ฆ„์ž…๋‹ˆ๋‹ค.

  • TASK_GROUP_NAME: ์„ธ๋ถ€์ •๋ณด๋ฅผ ๋ณด๋ ค๋Š” ํƒœ์Šคํฌ ๊ทธ๋ฃน์˜ ์ด๋ฆ„์ž…๋‹ˆ๋‹ค. ๊ฐ’์„ group0์œผ๋กœ ์„ค์ •ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

์›ํ•˜๋Š” ๊ฒฝ์šฐ ํ•„ํ„ฐ ํ‘œํ˜„์‹์— ๋”ฐ๋ผ ์ž‘์—…์˜ ํƒœ์Šคํฌ ๊ทธ๋ฃน์— ์žˆ๋Š” ํ•„ํ„ฐ๋ง๋œ ํƒœ์Šคํฌ ๋ชฉ๋ก์„ ๋ณด๊ธฐ ์œ„ํ•ด filter ์ฟผ๋ฆฌ ๋งค๊ฐœ๋ณ€์ˆ˜๋ฅผ ์ง€์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์˜ˆ๋ฅผ ๋“ค์–ด ๋‹ค์Œ GET ์š”์ฒญ์„ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค.

GET https://batch.googleapis.com/v1/projects/example-project/locations/us-central1/jobs/example-job/taskGroups/group0/tasks?filter=FILTER_EXPRESSION

FILTER_EXPRESSION์„ URL ์ธ์ฝ”๋”ฉ์„ ์‚ฌ์šฉํ•˜๋Š” ํ•„ํ„ฐ ํ‘œํ˜„์‹์œผ๋กœ ๋ฐ”๊ฟ‰๋‹ˆ๋‹ค.

์˜ˆ๋ฅผ ๋“ค์–ด ์‹คํ–‰ ์ค‘์ด๊ฑฐ๋‚˜ ์‹คํ–‰์„ ์„ฑ๊ณต์ ์œผ๋กœ ๋งˆ์นœ ์ž‘์—…์˜ ํƒœ์Šคํฌ ๊ทธ๋ฃน์— ์žˆ๋Š” ํƒœ์Šคํฌ๋งŒ ํ‘œ์‹œํ•˜๋„๋ก ๋‹ค์Œ ํ•„ํ„ฐ ํ‘œํ˜„์‹์„ ์ง€์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

STATE=RUNNING%20OR%20STATE=SUCCEEDED

URL๋กœ ์ธ์ฝ”๋”ฉ๋œ ํ•„ํ„ฐ ํ‘œํ˜„์‹์€ ๋‹ค์Œ ๋””์ฝ”๋”ฉ๋œ ํ•„ํ„ฐ ํ‘œํ˜„์‹์„ ๋‚˜ํƒ€๋ƒ…๋‹ˆ๋‹ค.

STATE=RUNNING OR STATE=SUCCEEDED

Go

Go

์ž์„ธํ•œ ๋‚ด์šฉ์€ Batch Go API ์ฐธ๊ณ  ๋ฌธ์„œ๋ฅผ ํ™•์ธํ•˜์„ธ์š”.

Batch์— ์ธ์ฆํ•˜๋ ค๋ฉด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ธฐ๋ณธ ์‚ฌ์šฉ์ž ์ธ์ฆ ์ •๋ณด๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. ์ž์„ธํ•œ ๋‚ด์šฉ์€ ๋กœ์ปฌ ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์˜ ์ธ์ฆ ์„ค์ •์„ ์ฐธ์กฐํ•˜์„ธ์š”.

import (
	"context"
	"fmt"
	"io"

	batch "cloud.google.com/go/batch/apiv1"
	"cloud.google.com/go/batch/apiv1/batchpb"
	"google.golang.org/api/iterator"
)

// Lists all tasks in the given project and region
func listTasks(w io.Writer, projectID, region, jobName, taskGroup string) error {
	// projectID := "your_project_id"
	// region := "us-central1"
	// jobName := "some-job"
	// taskGroup := "group0" // defaults to "group0" on job creation unless overridden

	ctx := context.Background()
	batchClient, err := batch.NewClient(ctx)
	if err != nil {
		return fmt.Errorf("NewClient: %w", err)
	}
	defer batchClient.Close()

	req := &batchpb.ListTasksRequest{
		Parent: fmt.Sprintf("projects/%s/locations/%s/jobs/%s/taskGroups/%s", projectID, region, jobName, taskGroup),
	}

	var tasks []*batchpb.Task
	it := batchClient.ListTasks(ctx, req)

	for {
		task, err := it.Next()
		if err == iterator.Done {
			break
		}
		if err != nil {
			return fmt.Errorf("unable to list tasks: %w", err)
		}
		tasks = append(tasks, task)
	}

	fmt.Fprintf(w, "Tasks: %v\n", tasks)

	return nil
}

์ž๋ฐ”

Java

์ž์„ธํ•œ ๋‚ด์šฉ์€ Batch Java API ์ฐธ๊ณ  ๋ฌธ์„œ๋ฅผ ํ™•์ธํ•˜์„ธ์š”.

Batch์— ์ธ์ฆํ•˜๋ ค๋ฉด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ธฐ๋ณธ ์‚ฌ์šฉ์ž ์ธ์ฆ ์ •๋ณด๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. ์ž์„ธํ•œ ๋‚ด์šฉ์€ ๋กœ์ปฌ ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์˜ ์ธ์ฆ ์„ค์ •์„ ์ฐธ์กฐํ•˜์„ธ์š”.

import com.google.cloud.batch.v1.BatchServiceClient;
import com.google.cloud.batch.v1.Task;
import java.io.IOException;

public class ListTasks {

  public static void main(String[] args) throws IOException {
    // TODO(developer): Replace these variables before running the sample.
    // Project ID or project number of the Cloud project you want to use.
    String projectId = "YOUR_PROJECT_ID";
    // Name of the region hosts the job.
    String region = "europe-central2";
    // Name of the job which tasks you want to list.
    String jobName = "JOB_NAME";
    // Name of the group of tasks. Usually it's `group0`.
    String groupName = "group0";

    listTasks(projectId, region, jobName, groupName);
  }

  // Get a list of all jobs defined in given region.
  public static void listTasks(String projectId, String region, String jobName, String groupName)
      throws IOException {
    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the `batchServiceClient.close()` method on the client to safely
    // clean up any remaining background resources.
    try (BatchServiceClient batchServiceClient = BatchServiceClient.create()) {

      String parent = String.format("projects/%s/locations/%s/jobs/%s/taskGroups/%s", projectId,
          region, jobName, groupName);
      for (Task task : batchServiceClient.listTasks(parent).iterateAll()) {
        System.out.println(task.getName());
      }
    }
  }
}

Node.js

Node.js

์ž์„ธํ•œ ๋‚ด์šฉ์€ Batch Node.js API ์ฐธ๊ณ  ๋ฌธ์„œ๋ฅผ ํ™•์ธํ•˜์„ธ์š”.

Batch์— ์ธ์ฆํ•˜๋ ค๋ฉด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ธฐ๋ณธ ์‚ฌ์šฉ์ž ์ธ์ฆ ์ •๋ณด๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. ์ž์„ธํ•œ ๋‚ด์šฉ์€ ๋กœ์ปฌ ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์˜ ์ธ์ฆ ์„ค์ •์„ ์ฐธ์กฐํ•˜์„ธ์š”.

/**
 * TODO(developer): Uncomment and replace these variables before running the sample.
 */
// const projectId = 'YOUR_PROJECT_ID';
/**
 * The region that hosts the job.
 */
// const region = 'us-central-1';
/**
 * The name of the job which tasks you want to list.
 */
// const jobName = 'YOUR_JOB_NAME';
/**
 * The name of the group of tasks. Usually it's `group0`.
 */
// const groupName = 'group0';

// Imports the Batch library
const batchLib = require('@google-cloud/batch');

// Instantiates a client
const batchClient = new batchLib.v1.BatchServiceClient();

async function callListTasks() {
  // Construct request
  const request = {
    parent: `projects/${projectId}/locations/${region}/jobs/${jobName}/taskGroups/${groupName}`,
  };

  // Run request
  const iterable = await batchClient.listTasksAsync(request);
  for await (const response of iterable) {
    console.log(response);
  }
}

await callListTasks();

Python

Python

์ž์„ธํ•œ ๋‚ด์šฉ์€ Batch Python API ์ฐธ๊ณ  ๋ฌธ์„œ๋ฅผ ํ™•์ธํ•˜์„ธ์š”.

Batch์— ์ธ์ฆํ•˜๋ ค๋ฉด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ธฐ๋ณธ ์‚ฌ์šฉ์ž ์ธ์ฆ ์ •๋ณด๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. ์ž์„ธํ•œ ๋‚ด์šฉ์€ ๋กœ์ปฌ ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์˜ ์ธ์ฆ ์„ค์ •์„ ์ฐธ์กฐํ•˜์„ธ์š”.

from __future__ import annotations

from collections.abc import Iterable

from google.cloud import batch_v1


def list_tasks(
    project_id: str, region: str, job_name: str, group_name: str
) -> Iterable[batch_v1.Task]:
    """
    Get a list of all jobs defined in given region.

    Args:
        project_id: project ID or project number of the Cloud project you want to use.
        region: name of the region hosting the jobs.
        job_name: name of the job which tasks you want to list.
        group_name: name of the group of tasks. Usually it's `group0`.

    Returns:
        An iterable collection of Task objects.
    """
    client = batch_v1.BatchServiceClient()

    return client.list_tasks(
        parent=f"projects/{project_id}/locations/{region}/jobs/{job_name}/taskGroups/{group_name}"
    )

C++

C++

์ž์„ธํ•œ ๋‚ด์šฉ์€ Batch C++ API ์ฐธ๊ณ  ๋ฌธ์„œ๋ฅผ ํ™•์ธํ•˜์„ธ์š”.

Batch์— ์ธ์ฆํ•˜๋ ค๋ฉด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ธฐ๋ณธ ์‚ฌ์šฉ์ž ์ธ์ฆ ์ •๋ณด๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. ์ž์„ธํ•œ ๋‚ด์šฉ์€ ๋กœ์ปฌ ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์˜ ์ธ์ฆ ์„ค์ •์„ ์ฐธ์กฐํ•˜์„ธ์š”.

#include "google/cloud/batch/v1/batch_client.h"

  [](std::string const& project_id, std::string const& location_id,
     std::string const& job_id, std::string const& group_id) {
    auto const parent = "projects/" + project_id + "/locations/" + location_id +
                        "/jobs/" + job_id + "/taskGroups/" + group_id;
    // Initialize a client and issue the request.
    auto client = google::cloud::batch_v1::BatchServiceClient(
        google::cloud::batch_v1::MakeBatchServiceConnection());
    int i = 0;
    for (auto task : client.ListTasks(parent)) {
      if (!task) throw std::move(task).status();
      std::cout << "Task[" << i++ << "]  " << task->DebugString() << "\n";
    }
  }

ํƒœ์Šคํฌ ์„ธ๋ถ€์ •๋ณด ๋ณด๊ธฐ

Google Cloud ์ฝ˜์†”, gcloud CLI, Batch API, Go, Java, Node.js, Python ๋˜๋Š” C++์„ ์‚ฌ์šฉํ•˜์—ฌ ํƒœ์Šคํฌ์˜ ์„ธ๋ถ€์ •๋ณด๋ฅผ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ฝ˜์†”

Google Cloud ์ฝ˜์†”์„ ์‚ฌ์šฉํ•˜์—ฌ ํƒœ์Šคํฌ ์„ธ๋ถ€์ •๋ณด๋ฅผ ๋ณด๋ ค๋ฉด ์ž‘์—… ์„ธ๋ถ€์ •๋ณด๋ฅผ ํ™•์ธํ•˜์—ฌ ์ž‘์—… ์„ธ๋ถ€์ •๋ณด ํŽ˜์ด์ง€๋ฅผ ์—ฝ๋‹ˆ๋‹ค. ๊ทธ๋Ÿฐ ๋‹ค์Œ ํƒœ์Šคํฌ ์„ธ๋ถ€์ •๋ณด ์„น์…˜์„ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.

gcloud

gcloud CLI๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํƒœ์Šคํฌ์˜ ์„ธ๋ถ€์ •๋ณด๋ฅผ ๋ณด๋ ค๋ฉด ๋‹ค์Œ ํ”Œ๋ž˜๊ทธ์™€ ํ•จ๊ป˜ gcloud batch tasks describe ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

gcloud batch tasks describe TASK_INDEX \
  --location=LOCATION \
  --job=JOB_NAME \
  --task_group=TASK_GROUP_NAME

๋‹ค์Œ์„ ๋ฐ”๊ฟ‰๋‹ˆ๋‹ค.

  • TASK_INDEX: ์„ธ๋ถ€์ •๋ณด๋ฅผ ๋ณด๋ ค๋Š” ํƒœ์Šคํฌ์˜ ์ƒ‰์ธ์ž…๋‹ˆ๋‹ค. ํƒœ์Šคํฌ ๊ทธ๋ฃน์˜ ํƒœ์Šคํฌ ์ƒ‰์ธ์€ ์ฒซ ๋ฒˆ์งธ ํƒœ์Šคํฌ์—์„œ 0๋ถ€ํ„ฐ ์‹œ์ž‘ํ•˜์—ฌ ํƒœ์Šคํฌ๋ฅผ ์ถ”๊ฐ€ํ•  ๋•Œ๋งˆ๋‹ค 1์”ฉ ์ฆ๊ฐ€ํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด ํƒœ์Šคํฌ 4๊ฐœ๊ฐ€ ํฌํ•จ๋œ ํƒœ์Šคํฌ ๊ทธ๋ฃน์˜ ์ƒ‰์ธ์€ 0, 1, 2, 3์ž…๋‹ˆ๋‹ค.

  • TASK_GROUP_NAME: ์„ธ๋ถ€์ •๋ณด๋ฅผ ๋ณด๋ ค๋Š” ํƒœ์Šคํฌ๊ฐ€ ํฌํ•จ๋œ ํƒœ์Šคํฌ ๊ทธ๋ฃน์˜ ์ด๋ฆ„์ž…๋‹ˆ๋‹ค. ๊ฐ’์„ group0์œผ๋กœ ์„ค์ •ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

  • JOB_NAME: ๊ธฐ์กด ์ž‘์—…์˜ ์ด๋ฆ„์ž…๋‹ˆ๋‹ค.

  • LOCATION: ์ž‘์—…์ด ์žˆ๋Š” ์œ„์น˜์ž…๋‹ˆ๋‹ค.

API

Batch API๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํƒœ์Šคํฌ์˜ ์„ธ๋ถ€์ •๋ณด๋ฅผ ๋ณด๋ ค๋ฉด tasks.get ๋ฉ”์„œ๋“œ์— ๋Œ€ํ•ด GET ์š”์ฒญ์„ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค.

GET https://batch.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/jobs/JOB_NAME/taskGroups/TASK_GROUP_NAME/tasks/TASK_INDEX

๋‹ค์Œ์„ ๋ฐ”๊ฟ‰๋‹ˆ๋‹ค.

  • PROJECT_ID: ํ˜„์žฌ ํ”„๋กœ์ ํŠธ์˜ ํ”„๋กœ์ ํŠธ ID์ž…๋‹ˆ๋‹ค.

  • LOCATION: ์ž‘์—…์ด ์žˆ๋Š” ์œ„์น˜์ž…๋‹ˆ๋‹ค.

  • JOB_NAME: ๊ธฐ์กด ์ž‘์—…์˜ ์ด๋ฆ„์ž…๋‹ˆ๋‹ค.

  • TASK_GROUP_NAME: ์„ธ๋ถ€์ •๋ณด๋ฅผ ๋ณด๋ ค๋Š” ํƒœ์Šคํฌ๊ฐ€ ํฌํ•จ๋œ ํƒœ์Šคํฌ ๊ทธ๋ฃน์˜ ์ด๋ฆ„์ž…๋‹ˆ๋‹ค. ๊ฐ’์„ group0์œผ๋กœ ์„ค์ •ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

  • TASK_INDEX: ์„ธ๋ถ€์ •๋ณด๋ฅผ ๋ณด๋ ค๋Š” ํƒœ์Šคํฌ์˜ ์ƒ‰์ธ์ž…๋‹ˆ๋‹ค. ํƒœ์Šคํฌ ๊ทธ๋ฃน์˜ ํƒœ์Šคํฌ ์ƒ‰์ธ์€ ์ฒซ ๋ฒˆ์งธ ํƒœ์Šคํฌ์—์„œ 0๋ถ€ํ„ฐ ์‹œ์ž‘ํ•˜์—ฌ ํƒœ์Šคํฌ๋ฅผ ์ถ”๊ฐ€ํ•  ๋•Œ๋งˆ๋‹ค 1์”ฉ ์ฆ๊ฐ€ํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด ํƒœ์Šคํฌ 4๊ฐœ๊ฐ€ ํฌํ•จ๋œ ํƒœ์Šคํฌ ๊ทธ๋ฃน์˜ ์ƒ‰์ธ์€ 0, 1, 2, 3์ž…๋‹ˆ๋‹ค.

Go

Go

์ž์„ธํ•œ ๋‚ด์šฉ์€ Batch Go API ์ฐธ๊ณ  ๋ฌธ์„œ๋ฅผ ํ™•์ธํ•˜์„ธ์š”.

Batch์— ์ธ์ฆํ•˜๋ ค๋ฉด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ธฐ๋ณธ ์‚ฌ์šฉ์ž ์ธ์ฆ ์ •๋ณด๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. ์ž์„ธํ•œ ๋‚ด์šฉ์€ ๋กœ์ปฌ ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์˜ ์ธ์ฆ ์„ค์ •์„ ์ฐธ์กฐํ•˜์„ธ์š”.

import (
	"context"
	"fmt"
	"io"

	batch "cloud.google.com/go/batch/apiv1"
	"cloud.google.com/go/batch/apiv1/batchpb"
)

// Retrieves the information about the specified job, most importantly its status
func getTask(w io.Writer, projectID, region, jobName, taskGroup string, taskNumber int32) error {
	// projectID := "your_project_id"
	// region := "us-central1"
	// jobName := "some-job"
	// taskGroup := "group0" // defaults to "group0" on job creation unless overridden
	// taskNumber := 0

	ctx := context.Background()
	batchClient, err := batch.NewClient(ctx)
	if err != nil {
		return fmt.Errorf("NewClient: %w", err)
	}
	defer batchClient.Close()

	req := &batchpb.GetTaskRequest{
		Name: fmt.Sprintf("projects/%s/locations/%s/jobs/%s/taskGroups/%s/tasks/%d",
			projectID, region, jobName, taskGroup, taskNumber),
	}

	response, err := batchClient.GetTask(ctx, req)
	if err != nil {
		return fmt.Errorf("unable to get task: %w", err)
	}

	fmt.Fprintf(w, "Task info: %v\n", response)

	return nil
}

์ž๋ฐ”

Java

์ž์„ธํ•œ ๋‚ด์šฉ์€ Batch Java API ์ฐธ๊ณ  ๋ฌธ์„œ๋ฅผ ํ™•์ธํ•˜์„ธ์š”.

Batch์— ์ธ์ฆํ•˜๋ ค๋ฉด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ธฐ๋ณธ ์‚ฌ์šฉ์ž ์ธ์ฆ ์ •๋ณด๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. ์ž์„ธํ•œ ๋‚ด์šฉ์€ ๋กœ์ปฌ ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์˜ ์ธ์ฆ ์„ค์ •์„ ์ฐธ์กฐํ•˜์„ธ์š”.

import com.google.cloud.batch.v1.BatchServiceClient;
import com.google.cloud.batch.v1.Task;
import com.google.cloud.batch.v1.TaskName;
import java.io.IOException;

public class GetTask {

  public static void main(String[] args) throws IOException {
    // TODO(developer): Replace these variables before running the sample.
    // Project ID or project number of the Cloud project you want to use.
    String projectId = "YOUR_PROJECT_ID";
    // Name of the region hosts the job.
    String region = "europe-central2";
    // The name of the job you want to retrieve information about.
    String jobName = "JOB_NAME";
    // The name of the group that owns the task you want to check. Usually it's `group0`.
    String groupName = "group0";
    // Number of the task you want to look up.
    int taskNumber = 0;

    getTask(projectId, region, jobName, groupName, taskNumber);
  }

  // Retrieve information about a Task.
  public static void getTask(String projectId, String region, String jobName, String groupName,
      int taskNumber) throws IOException {
    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the `batchServiceClient.close()` method on the client to safely
    // clean up any remaining background resources.
    try (BatchServiceClient batchServiceClient = BatchServiceClient.create()) {

      Task task = batchServiceClient.getTask(TaskName.newBuilder()
          .setProject(projectId)
          .setLocation(region)
          .setJob(jobName)
          .setTaskGroup(groupName)
          .setTask(String.valueOf(taskNumber))
          .build());
      System.out.printf("Retrieved task information: %s", task.getName());
    }
  }
}

Node.js

Node.js

์ž์„ธํ•œ ๋‚ด์šฉ์€ Batch Node.js API ์ฐธ๊ณ  ๋ฌธ์„œ๋ฅผ ํ™•์ธํ•˜์„ธ์š”.

Batch์— ์ธ์ฆํ•˜๋ ค๋ฉด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ธฐ๋ณธ ์‚ฌ์šฉ์ž ์ธ์ฆ ์ •๋ณด๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. ์ž์„ธํ•œ ๋‚ด์šฉ์€ ๋กœ์ปฌ ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์˜ ์ธ์ฆ ์„ค์ •์„ ์ฐธ์กฐํ•˜์„ธ์š”.

/**
 * TODO(developer): Uncomment and replace these variables before running the sample.
 */
// const projectId = 'YOUR_PROJECT_ID';
/**
 * The region that hosts the job.
 */
// const region = 'us-central-1';
/**
 * The name of the job you want to retrieve information about.
 */
// const jobName = 'YOUR_JOB_NAME';
/**
 * The name of the group that owns the task you want to check.
 * Usually it's `group0`.
 */
// const groupName = 'group0';
/**
 * The number of the task you want to look up.
 */
// const taskNumber = 0;

// Imports the Batch library
const batchLib = require('@google-cloud/batch');

// Instantiates a client
const batchClient = new batchLib.v1.BatchServiceClient();

async function callGetJob() {
  // Construct request
  const request = {
    name:
      `projects/${projectId}/locations/${region}/jobs/${jobName}` +
      `/taskGroups/${groupName}/tasks/${taskNumber}`,
  };

  // Run request
  const response = await batchClient.getTask(request);
  console.log(response);
}

await callGetJob();

Python

Python

์ž์„ธํ•œ ๋‚ด์šฉ์€ Batch Python API ์ฐธ๊ณ  ๋ฌธ์„œ๋ฅผ ํ™•์ธํ•˜์„ธ์š”.

Batch์— ์ธ์ฆํ•˜๋ ค๋ฉด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ธฐ๋ณธ ์‚ฌ์šฉ์ž ์ธ์ฆ ์ •๋ณด๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. ์ž์„ธํ•œ ๋‚ด์šฉ์€ ๋กœ์ปฌ ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์˜ ์ธ์ฆ ์„ค์ •์„ ์ฐธ์กฐํ•˜์„ธ์š”.


from google.cloud import batch_v1


def get_task(
    project_id: str, region: str, job_name: str, group_name: str, task_number: int
) -> batch_v1.Task:
    """
    Retrieve information about a Task.

    Args:
        project_id: project ID or project number of the Cloud project you want to use.
        region: name of the region hosts the job.
        job_name: the name of the job you want to retrieve information about.
        group_name: the name of the group that owns the task you want to check. Usually it's `group0`.
        task_number: number of the task you want to look up.

    Returns:
        A Task object representing the specified task.
    """
    client = batch_v1.BatchServiceClient()

    return client.get_task(
        name=f"projects/{project_id}/locations/{region}/jobs/{job_name}"
        f"/taskGroups/{group_name}/tasks/{task_number}"
    )

C++

C++

์ž์„ธํ•œ ๋‚ด์šฉ์€ Batch C++ API ์ฐธ๊ณ  ๋ฌธ์„œ๋ฅผ ํ™•์ธํ•˜์„ธ์š”.

Batch์— ์ธ์ฆํ•˜๋ ค๋ฉด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ธฐ๋ณธ ์‚ฌ์šฉ์ž ์ธ์ฆ ์ •๋ณด๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. ์ž์„ธํ•œ ๋‚ด์šฉ์€ ๋กœ์ปฌ ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์˜ ์ธ์ฆ ์„ค์ •์„ ์ฐธ์กฐํ•˜์„ธ์š”.

#include "google/cloud/batch/v1/batch_client.h"

  [](std::string const& project_id, std::string const& location_id,
     std::string const& job_id, std::string const& group_id,
     std::string const& task_number) {
    auto const name = "projects/" + project_id + "/locations/" + location_id +
                      "/jobs/" + job_id + "/taskGroups/" + group_id +
                      "/tasks/" + task_number;
    // Initialize a client and issue the request.
    auto client = google::cloud::batch_v1::BatchServiceClient(
        google::cloud::batch_v1::MakeBatchServiceConnection());
    auto response = client.GetTask(name);
    if (!response) throw std::move(response).status();
    std::cout << "GetTask() succeeded with " << response->DebugString() << "\n";
  }

๋‹ค์Œ ๋‹จ๊ณ„