2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

BigQueryで実行中のジョブをまとめてキャンセルしたい

Last updated at Posted at 2022-02-02

概要

不幸な事故によって無駄なBigQueryのジョブが大量に流れてしまった際に、一斉にジョブをキャンセルしたい時の手順を備忘のために掲載する。

やり方

bqコマンドで以下を実行する。

bq ls --jobs=true --max_results=100 | grep "RUNNING" | cut -d ' ' -f 3 |while read job; do bq cancel ${job}; done

※環境・権限によって意図しない動作となる場合があるため、利用時は注意

なお、bqコマンドの実行には、自前の環境にSDKをインストールする方法の他に、ブラウザのコンソール上から利用できるcloud shellを使う方法も存在する。

参考: Cloud Shell の使用  |  Google Cloud

詳細

bq ls --jobs=true --max_results=100

status問わずジョブを一覧表示
max_resultsで表示件数を指定するので、ここは任意
statusによる絞り込みができるオプションは存在しない?ようなので、後段で処理

bq ls --jobs=true --max_results=100 | grep "RUNNING"

RUNNING行を取り出す(=status=RUNNINGに絞り込む)

bq ls --jobs=true --max_results=100 | grep "RUNNING" | cut -d ' ' -f 3

JobID列に絞り込む

bq ls --jobs=true --max_results=100 | grep "RUNNING" | cut -d ' ' -f 3 |while read job; do bq cancel ${job}; done

複数のJobIDを一度に処理できないようなので、1つのIDごとに処理
このままだと各ジョブでキャンセル完了まで応答待ち状態を挟む挙動となるが、--nosyncを入れると応答待たずにコマンドが完了するのでお好みで

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?