1
2

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 5 years have passed since last update.

digdagのtd.last_resultsの保存

Last updated at Posted at 2016-11-18

以下、digdagのver.は0.8.21

困ったこと

以下のようにtd>を2回呼び出すと、1回めの結果を保存しておいた変数が2回めの実行後に書き換わってしまう

!include : config.dig

+td1:
  td>: a.sql
  store_last_results: true
+group: # td結果を保存したいがためだけのグループ
  _export:
    result1: ${td.last_results.result1}
    result2: ${td.last_results.result2}
  +show_results1:
    echo>: result1=${result1}, result2=${result2}
  +td2:
    td>: b.sql
    store_last_results: true
  +show_results2:
    echo>: result1=${result1}, result2=${result2}
    # b.sqlの結果に書き換わってしまう

調べてわかったこと

以下に理由とworkaroundが書かれていた

  • JavaScriptが参照のたびに実行される https://github.com/treasure-data/digdag/issues/351
    • JavaScriptはタスク開始時に実行される(_export時点では実行されない)
    • for_each>で先に実行しておくworkaroundがある
    • 驚かれる挙動だと思うので変えたいかも

解決

workaroundを適用すると以下になる

!include : config.dig

+td1:
  td>: a.sql
  store_last_results: true
+group: # td結果を保存したいがためだけのグループ
  for_each>:
    result1: ["${td.last_results.result1}"]
    result2: ["${td.last_results.result2}"]
  _do:
    +show_results1:
      echo>: result1=${result1}, result2=${result2}
    +td2:
      td>: b.sql
      store_last_results: true
    +show_results2:
      echo>: result1=${result1}, result2=${result2}
      # a.sqlの結果のまま
1
2
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
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?