[why] if job.yaml define: on_fail: on_fail_sleep: XXXX(time) XXXX: XXXX ... [how] By sh_on_fail, it will appear in job.sh: on_fail() { sleep: on_fail[on_fail_sleep] XXXX: XXXX ... }
Signed-off-by: Hu XueJiao huxuejiao1@huawei.com --- lib/job2sh.rb | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-)
diff --git a/lib/job2sh.rb b/lib/job2sh.rb index 9c95ff4b..974b78b7 100755 --- a/lib/job2sh.rb +++ b/lib/job2sh.rb @@ -142,7 +142,7 @@ class Job2sh < Job end
def parse_one(ancestors, key, val, pass) - if ['pp', 'define_files', 'monitors'].include?(key) + if ['pp', 'define_files', 'monitors', 'on_fail'].include?(key) return false end tabs = indent(ancestors) @@ -266,9 +266,11 @@ class Job2sh < Job sh_run_job(job) local_script_lines += @script_lines
- sh_extract_stats(job) local_script_lines += @script_lines + + sh_on_fail() + local_script_lines += @script_lines
sh_define_files()
@@ -338,6 +340,23 @@ class Job2sh < Job @script_lines end
+ def sh_on_fail + @script_lines = [] + + job = (@jobx || @job) + on_fail = job['on_fail'] || {} + + out_line 'on_fail()' + out_line '{' + out_line + on_fail.each do |key, val| + if key == "on_fail_sleep" + out_line "\tsleep #{on_fail[key]}" + end + end + out_line '}' + end + def sh_define_files @script_lines = []
On Thu, Oct 29, 2020 at 08:57:10PM +0800, Hu Xuejiao wrote:
[why] if job.yaml define: on_fail: on_fail_sleep: XXXX(time) XXXX: XXXX ... [how] By sh_on_fail, it will appear in job.sh: on_fail() { sleep: on_fail[on_fail_sleep] XXXX: XXXX ... }
Signed-off-by: Hu XueJiao huxuejiao1@huawei.com
lib/job2sh.rb | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-)
diff --git a/lib/job2sh.rb b/lib/job2sh.rb index 9c95ff4b..974b78b7 100755 --- a/lib/job2sh.rb +++ b/lib/job2sh.rb @@ -142,7 +142,7 @@ class Job2sh < Job end
def parse_one(ancestors, key, val, pass)
- if ['pp', 'define_files', 'monitors'].include?(key)
- if ['pp', 'define_files', 'monitors', 'on_fail'].include?(key) return false end tabs = indent(ancestors)
@@ -266,9 +266,11 @@ class Job2sh < Job sh_run_job(job) local_script_lines += @script_lines
- sh_extract_stats(job) local_script_lines += @script_lines
- sh_on_fail()
delete () if no parameters
local_script_lines += @script_lines
sh_define_files()
@@ -338,6 +340,23 @@ class Job2sh < Job @script_lines end
- def sh_on_fail
- @script_lines = []
- job = (@jobx || @job)
- on_fail = job['on_fail'] || {}
- out_line 'on_fail()'
ditto
- out_line '{'
- out_line
- on_fail.each do |key, val|
if key == "on_fail_sleep"
out_line "\tsleep #{on_fail[key]}"
end
three line => out_line "\tsleep #{on_fail[key]}" if key == "on_fail_sleep"
Thanks Luan Shengde
- end
- out_line '}'
- end
- def sh_define_files @script_lines = []
-- 2.23.0
add: add ? ==> job2sh: add on_fail to job.sh
On Thu, Oct 29, 2020 at 08:57:10PM +0800, Hu Xuejiao wrote:
[why] if job.yaml define: on_fail: on_fail_sleep: XXXX(time) XXXX: XXXX ... [how] By sh_on_fail, it will appear in job.sh: on_fail() { sleep: on_fail[on_fail_sleep] XXXX: XXXX ... }
Signed-off-by: Hu XueJiao huxuejiao1@huawei.com
lib/job2sh.rb | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-)
diff --git a/lib/job2sh.rb b/lib/job2sh.rb index 9c95ff4b..974b78b7 100755 --- a/lib/job2sh.rb +++ b/lib/job2sh.rb @@ -142,7 +142,7 @@ class Job2sh < Job end
def parse_one(ancestors, key, val, pass)
- if ['pp', 'define_files', 'monitors'].include?(key)
- if ['pp', 'define_files', 'monitors', 'on_fail'].include?(key) return false end tabs = indent(ancestors)
@@ -266,9 +266,11 @@ class Job2sh < Job sh_run_job(job) local_script_lines += @script_lines
- sh_extract_stats(job) local_script_lines += @script_lines
sh_on_fail()
local_script_lines += @script_lines
sh_define_files()
@@ -338,6 +340,23 @@ class Job2sh < Job @script_lines end
- def sh_on_fail
- @script_lines = []
- job = (@jobx || @job)
- on_fail = job['on_fail'] || {}
- out_line 'on_fail()'
- out_line '{'
- out_line
- on_fail.each do |key, val|
if key == "on_fail_sleep"
out_line "\tsleep #{on_fail[key]}"
end
- end
- out_line '}'
- end
- def sh_define_files @script_lines = []
-- 2.23.0
It should support this in job.yaml
on_fail: whatever-program: param: xx
Which should be turned into this in job.sh
on_fail() { param=xx whatever-program }
Actually current job2sh code will already define on_fail(). Just need move the definition to top level.
Thanks, Fengguang
On Thu, Oct 29, 2020 at 08:57:10PM +0800, Hu Xuejiao wrote:
[why] if job.yaml define: on_fail: on_fail_sleep: XXXX(time) XXXX: XXXX ... [how] By sh_on_fail, it will appear in job.sh: on_fail() { sleep: on_fail[on_fail_sleep] XXXX: XXXX ... }
Signed-off-by: Hu XueJiao huxuejiao1@huawei.com
lib/job2sh.rb | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-)
diff --git a/lib/job2sh.rb b/lib/job2sh.rb index 9c95ff4b..974b78b7 100755 --- a/lib/job2sh.rb +++ b/lib/job2sh.rb @@ -142,7 +142,7 @@ class Job2sh < Job end
def parse_one(ancestors, key, val, pass)
- if ['pp', 'define_files', 'monitors'].include?(key)
- if ['pp', 'define_files', 'monitors', 'on_fail'].include?(key) return false end tabs = indent(ancestors)
@@ -266,9 +266,11 @@ class Job2sh < Job sh_run_job(job) local_script_lines += @script_lines
- sh_extract_stats(job) local_script_lines += @script_lines
sh_on_fail()
local_script_lines += @script_lines
sh_define_files()
@@ -338,6 +340,23 @@ class Job2sh < Job @script_lines end
- def sh_on_fail
- @script_lines = []
- job = (@jobx || @job)
- on_fail = job['on_fail'] || {}
- out_line 'on_fail()'
- out_line '{'
- out_line
- on_fail.each do |key, val|
if key == "on_fail_sleep"
out_line "\tsleep #{on_fail[key]}"
end
- end
- out_line '}'
- end
- def sh_define_files @script_lines = []
-- 2.23.0