1) after job finished, we save update job field back to es. 2) if the job is consumed at "20201010", but finished at "20201011". then the result_root will be update to "/result/$suite/$tbox_group/20201011/$id". 3) but the result is really saved at "/result/$suite/$tbox_group/20201010/$id", 20201010 is the date when it is consumed.
no need to set_default for an initialized job (when is is consumed).
Signed-off-by: Tong Qunfeng taxcom@tom.com --- src/lib/job.cr | 40 +++++++++++++++++++++++++++++++++++++--- src/lib/sched.cr | 1 + 2 files changed, 38 insertions(+), 3 deletions(-)
diff --git a/src/lib/job.cr b/src/lib/job.cr index 504bc19..be3446e 100644 --- a/src/lib/job.cr +++ b/src/lib/job.cr @@ -50,10 +50,13 @@ class Job @hash = job_content.as_h
# init job with "-1", or use the original job_content["id"] - if "#{id}" == "" - @hash["id"] = JSON::Any.new("-1") + id == "-1" if "#{id}" == "" + + if initialized? + return if @hash["id"] == "#{id}" end
+ @hash["id"] = JSON::Any.new("#{id}") check_required_keys() set_defaults() end @@ -165,7 +168,7 @@ class Job self["os_dir"] = "#{os}/#{os_arch}/#{os_version}" end
- private def set_result_root + def set_result_root update_tbox_group_from_testbox # id must exists, need update tbox_group date = Time.local.to_s("%F") self["result_root"] = "/result/#{suite}/#{tbox_group}/#{date}/#{id}" @@ -234,6 +237,37 @@ class Job end end
+ private def initialized? + initialized_keys = [] of String + + REQUIRED_KEYS.each do |key| + initialized_keys << key.to_s + end + + METHOD_KEYS.each do |key| + initialized_keys << key.to_s + end + + INIT_FIELD.each do |key, _value| + initialized_keys << key.to_s + end + + initialized_keys += ["result_service", + "LKP_SERVER", + "LKP_CGI_PORT", + "SCHED_HOST", + "SCHED_PORT"] + + initialized_keys.each do |key| + if @hash.has_key?(key) == false + return false + end + end + + return false if "#{@hash["id"]}" == "" + return true + end + private def vmlinuz if os_mount == "initramfs" return "#{INITRD_HTTP_PREFIX}" + diff --git a/src/lib/sched.cr b/src/lib/sched.cr index 23332df..2fbf05d 100644 --- a/src/lib/sched.cr +++ b/src/lib/sched.cr @@ -451,6 +451,7 @@ class Sched
if job job.update({"testbox" => testbox}) + job.set_result_root @redis.set_job(job) end return job