Skip to content

Instantly share code, notes, and snippets.

@buzztaiki
Last active June 25, 2020 16:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save buzztaiki/68f7b72d0e51c1d3106eaf96662c2c75 to your computer and use it in GitHub Desktop.
Save buzztaiki/68f7b72d0e51c1d3106eaf96662c2c75 to your computer and use it in GitHub Desktop.
Digdag Variable Scope
  • export は子供にだけ公開される。
  • subtask で store しても親に反映される。
# frozen_string_literal: true
class StoreTask
def call(name:)
Digdag.env.store(name.to_sym => name)
end
end
class ExportAndChildTask
def call(name:)
Digdag.env.export(name.to_sym => name)
Digdag.env.add_subtask(EchoTask, :call, var: name)
end
end
class StoreAndChildTask
def call(name:)
Digdag.env.store(name.to_sym => name)
Digdag.env.add_subtask(EchoTask, :call, var: name)
end
end
class EchoTask
def call(var:)
puts var
end
end
timezone: UTC
_export:
rb:
require: 'tasks'
+step1:
_export:
export_step1: export_step1
+step1_1:
echo>: ${export_step1}
+step2:
rb>: ExportAndChildTask.call
name: export_step2
+step3:
rb>: StoreAndChildTask.call
name: store_step3
+step4:
+step4_1:
rb>: StoreTask.call
name: store_step4_1
+step4_2:
echo>: ${store_step4_1}
# ERROR!
# +echo1:
# echo>: ${export_step1}
# ERROR!
# +echo2:
# echo>: ${export_step2}
+echo3:
echo>: ${store_step3}
+echo4:
echo>: ${store_step4_1}
@buzztaiki
Copy link
Author

digdag run -a --no-save variable_scope.dig 
2020-06-26 01:12:08 +0900: Digdag v0.9.16
2020-06-26 01:12:09 +0900 [WARN] (main): Using a new session time 2020-06-25T00:00:00+00:00.
2020-06-26 01:12:09 +0900 [INFO] (main): Starting a new session project id=1 workflow name=variable_scope session_time=2020-06-25T00:00:00+00:00
2020-06-26 01:12:10 +0900 [INFO] (0016@[0:default]+variable_scope+step1+step1_1): echo>: export_step1
export_step1
2020-06-26 01:12:10 +0900 [INFO] (0016@[0:default]+variable_scope+step2): rb>: ExportAndChildTask.call
2020-06-26 01:12:11 +0900 [INFO] (0016@[0:default]+variable_scope+step2^sub+subtask0): rb>: ::EchoTask.call
export_step2
2020-06-26 01:12:11 +0900 [INFO] (0016@[0:default]+variable_scope+step3): rb>: StoreAndChildTask.call
2020-06-26 01:12:12 +0900 [INFO] (0016@[0:default]+variable_scope+step3^sub+subtask0): rb>: ::EchoTask.call
store_step3
2020-06-26 01:12:12 +0900 [INFO] (0016@[0:default]+variable_scope+step4+step4_1): rb>: StoreTask.call
2020-06-26 01:12:12 +0900 [INFO] (0016@[0:default]+variable_scope+step4+step4_2): echo>: store_step4_1
store_step4_1
2020-06-26 01:12:13 +0900 [INFO] (0016@[0:default]+variable_scope+echo3): echo>: store_step3
store_step3
2020-06-26 01:12:13 +0900 [INFO] (0016@[0:default]+variable_scope+echo4): echo>: store_step4_1
store_step4_1
Success.
  * Use --session <daily | hourly | "yyyy-MM-dd[ HH:mm:ss]"> to not reuse the last session time.
  * Use --rerun, --start +NAME, or --goal +NAME argument to rerun skipped tasks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment