[Why] fix ameba warning. def submit_job() begin xxx rescue xxx end end [How] def submit_job() xxx rescue xxx end [warning info] /code/compass-ci/src/lib/sched.cr:162:3 [C] Style/RedundantBegin: Redundant `begin` block detected
def submit_job(env : HTTP::Server::Context)
^ Finished in 132.19 milliseconds
1 inspected, 1 failure.
Signed-off-by: Wu Zhende wuzhende666@163.com --- src/lib/sched.cr | 48 +++++++++++++++++++++++------------------------- 1 file changed, 23 insertions(+), 25 deletions(-)
diff --git a/src/lib/sched.cr b/src/lib/sched.cr index c32091f..f3a7b1c 100644 --- a/src/lib/sched.cr +++ b/src/lib/sched.cr @@ -160,32 +160,30 @@ class Sched end
def submit_job(env : HTTP::Server::Context) - begin - body = env.request.body.not_nil!.gets_to_end - - job_content = JSON.parse(body) - job = Job.new(job_content, job_content["id"]?) - job["commit_date"] = get_commit_date(job) - - # it is not a cluster job if cluster field is empty or - # field's prefix is 'cs-localhost' - cluster_file = job["cluster"] - if cluster_file.empty? || cluster_file.starts_with?("cs-localhost") - return submit_single_job(job) - else - cluster_config = get_cluster_config(cluster_file, - job.lkp_initrd_user, - job.os_arch) - return submit_cluster_job(job, cluster_config) - end - rescue ex - puts ex.inspect_with_backtrace - return [{ - "job_id" => "0", - "message" => ex.to_s, - "job_state" => "submit", - }] + body = env.request.body.not_nil!.gets_to_end + + job_content = JSON.parse(body) + job = Job.new(job_content, job_content["id"]?) + job["commit_date"] = get_commit_date(job) + + # it is not a cluster job if cluster field is empty or + # field's prefix is 'cs-localhost' + cluster_file = job["cluster"] + if cluster_file.empty? || cluster_file.starts_with?("cs-localhost") + return submit_single_job(job) + else + cluster_config = get_cluster_config(cluster_file, + job.lkp_initrd_user, + job.os_arch) + return submit_cluster_job(job, cluster_config) end + rescue ex + puts ex.inspect_with_backtrace + return [{ + "job_id" => "0", + "message" => ex.to_s, + "job_state" => "submit", + }] end
# return:
I think to display begin will more clear.
Thanks, Xueliang
On Wed, Oct 28, 2020 at 06:05:02PM +0800, Wu Zhende wrote:
[Why] fix ameba warning. def submit_job() begin xxx rescue xxx end end [How] def submit_job() xxx rescue xxx end [warning info] /code/compass-ci/src/lib/sched.cr:162:3 [C] Style/RedundantBegin: Redundant `begin` block detected
def submit_job(env : HTTP::Server::Context)
^ Finished in 132.19 milliseconds
1 inspected, 1 failure.
Signed-off-by: Wu Zhende wuzhende666@163.com
src/lib/sched.cr | 48 +++++++++++++++++++++++------------------------- 1 file changed, 23 insertions(+), 25 deletions(-)
diff --git a/src/lib/sched.cr b/src/lib/sched.cr index c32091f..f3a7b1c 100644 --- a/src/lib/sched.cr +++ b/src/lib/sched.cr @@ -160,32 +160,30 @@ class Sched end
def submit_job(env : HTTP::Server::Context)
- begin
body = env.request.body.not_nil!.gets_to_end
job_content = JSON.parse(body)
job = Job.new(job_content, job_content["id"]?)
job["commit_date"] = get_commit_date(job)
# it is not a cluster job if cluster field is empty or
# field's prefix is 'cs-localhost'
cluster_file = job["cluster"]
if cluster_file.empty? || cluster_file.starts_with?("cs-localhost")
return submit_single_job(job)
else
cluster_config = get_cluster_config(cluster_file,
job.lkp_initrd_user,
job.os_arch)
return submit_cluster_job(job, cluster_config)
end
- rescue ex
puts ex.inspect_with_backtrace
return [{
"job_id" => "0",
"message" => ex.to_s,
"job_state" => "submit",
}]
body = env.request.body.not_nil!.gets_to_end
job_content = JSON.parse(body)
job = Job.new(job_content, job_content["id"]?)
job["commit_date"] = get_commit_date(job)
# it is not a cluster job if cluster field is empty or
# field's prefix is 'cs-localhost'
cluster_file = job["cluster"]
if cluster_file.empty? || cluster_file.starts_with?("cs-localhost")
return submit_single_job(job)
else
cluster_config = get_cluster_config(cluster_file,
job.lkp_initrd_user,
job.os_arch)
return submit_cluster_job(job, cluster_config)
end
rescue ex
puts ex.inspect_with_backtrace
return [{
"job_id" => "0",
"message" => ex.to_s,
"job_state" => "submit",
}] end
# return:
-- 2.23.0
On Wed, Oct 28, 2020 at 07:28:55PM +0800, Cao Xueliang wrote:
I think to display begin will more clear.
It's a short syntax form: assume a method or block definition is an implicit `begin ... end` expression, then specify `rescue`, `else`, and `ensure` clauses.
The body of function **submit_job** is in exception `begin` part.
Thanks, RenWen
Thanks, Xueliang
On Wed, Oct 28, 2020 at 06:05:02PM +0800, Wu Zhende wrote:
[Why] fix ameba warning. def submit_job() begin xxx rescue xxx end end [How] def submit_job() xxx rescue xxx end [warning info] /code/compass-ci/src/lib/sched.cr:162:3 [C] Style/RedundantBegin: Redundant `begin` block detected
def submit_job(env : HTTP::Server::Context)
^ Finished in 132.19 milliseconds
1 inspected, 1 failure.
Signed-off-by: Wu Zhende wuzhende666@163.com
src/lib/sched.cr | 48 +++++++++++++++++++++++------------------------- 1 file changed, 23 insertions(+), 25 deletions(-)
diff --git a/src/lib/sched.cr b/src/lib/sched.cr index c32091f..f3a7b1c 100644 --- a/src/lib/sched.cr +++ b/src/lib/sched.cr @@ -160,32 +160,30 @@ class Sched end
def submit_job(env : HTTP::Server::Context)
- begin
body = env.request.body.not_nil!.gets_to_end
job_content = JSON.parse(body)
job = Job.new(job_content, job_content["id"]?)
job["commit_date"] = get_commit_date(job)
# it is not a cluster job if cluster field is empty or
# field's prefix is 'cs-localhost'
cluster_file = job["cluster"]
if cluster_file.empty? || cluster_file.starts_with?("cs-localhost")
return submit_single_job(job)
else
cluster_config = get_cluster_config(cluster_file,
job.lkp_initrd_user,
job.os_arch)
return submit_cluster_job(job, cluster_config)
end
- rescue ex
puts ex.inspect_with_backtrace
return [{
"job_id" => "0",
"message" => ex.to_s,
"job_state" => "submit",
}]
body = env.request.body.not_nil!.gets_to_end
job_content = JSON.parse(body)
job = Job.new(job_content, job_content["id"]?)
job["commit_date"] = get_commit_date(job)
# it is not a cluster job if cluster field is empty or
# field's prefix is 'cs-localhost'
cluster_file = job["cluster"]
if cluster_file.empty? || cluster_file.starts_with?("cs-localhost")
return submit_single_job(job)
else
cluster_config = get_cluster_config(cluster_file,
job.lkp_initrd_user,
job.os_arch)
return submit_cluster_job(job, cluster_config)
end
rescue ex
puts ex.inspect_with_backtrace
return [{
"job_id" => "0",
"message" => ex.to_s,
"job_state" => "submit",
}] end
# return:
-- 2.23.0
On Wed, Oct 28, 2020 at 07:41:31PM +0800, Ren Wen wrote:
On Wed, Oct 28, 2020 at 07:28:55PM +0800, Cao Xueliang wrote:
I think to display begin will more clear.
It's a short syntax form: assume a method or block definition is an implicit `begin ... end` expression, then specify `rescue`, `else`, and `ensure` clauses.
The body of function **submit_job** is in exception `begin` part.
Cant agree this, the source of crystal use begin ensure end.
Thanks, Xueliang
Thanks, RenWen
Thanks, Xueliang
On Wed, Oct 28, 2020 at 06:05:02PM +0800, Wu Zhende wrote:
[Why] fix ameba warning. def submit_job() begin xxx rescue xxx end end [How] def submit_job() xxx rescue xxx end [warning info] /code/compass-ci/src/lib/sched.cr:162:3 [C] Style/RedundantBegin: Redundant `begin` block detected
def submit_job(env : HTTP::Server::Context)
^ Finished in 132.19 milliseconds
1 inspected, 1 failure.
Signed-off-by: Wu Zhende wuzhende666@163.com
src/lib/sched.cr | 48 +++++++++++++++++++++++------------------------- 1 file changed, 23 insertions(+), 25 deletions(-)
diff --git a/src/lib/sched.cr b/src/lib/sched.cr index c32091f..f3a7b1c 100644 --- a/src/lib/sched.cr +++ b/src/lib/sched.cr @@ -160,32 +160,30 @@ class Sched end
def submit_job(env : HTTP::Server::Context)
- begin
body = env.request.body.not_nil!.gets_to_end
job_content = JSON.parse(body)
job = Job.new(job_content, job_content["id"]?)
job["commit_date"] = get_commit_date(job)
# it is not a cluster job if cluster field is empty or
# field's prefix is 'cs-localhost'
cluster_file = job["cluster"]
if cluster_file.empty? || cluster_file.starts_with?("cs-localhost")
return submit_single_job(job)
else
cluster_config = get_cluster_config(cluster_file,
job.lkp_initrd_user,
job.os_arch)
return submit_cluster_job(job, cluster_config)
end
- rescue ex
puts ex.inspect_with_backtrace
return [{
"job_id" => "0",
"message" => ex.to_s,
"job_state" => "submit",
}]
body = env.request.body.not_nil!.gets_to_end
job_content = JSON.parse(body)
job = Job.new(job_content, job_content["id"]?)
job["commit_date"] = get_commit_date(job)
# it is not a cluster job if cluster field is empty or
# field's prefix is 'cs-localhost'
cluster_file = job["cluster"]
if cluster_file.empty? || cluster_file.starts_with?("cs-localhost")
return submit_single_job(job)
else
cluster_config = get_cluster_config(cluster_file,
job.lkp_initrd_user,
job.os_arch)
return submit_cluster_job(job, cluster_config)
end
rescue ex
puts ex.inspect_with_backtrace
return [{
"job_id" => "0",
"message" => ex.to_s,
"job_state" => "submit",
}] end
# return:
-- 2.23.0