+++ b/src/extract-stats/stats_worker.cr @@ -22,6 +22,8 @@ class StatsWorker if job_id # will consume the job by post-processing job = @es.get_job_content(job_id) result_root = job["result_root"]?
define_files = job["define_files"]?
write_user_stats(result_root.to_s, define_files.as_h) if define_files.is_a?(JSON::Any) result_post_processing(job_id, result_root.to_s, queue_path) @tq.delete_task(queue_path + "/in_process", "#{job_id}") end
@@ -139,4 +141,17 @@ class StatsWorker STDERR.puts e.message end end
- def write_user_stats(result_root : String, define_files : Hash(String, JSON::Any))
- return nil unless result_root && File.exists?(result_root)
^------ delete "nil" ? function caller doesn't need to receive a return value.
we can delete "nil" but write "nil" looks more clearly
- define_files.each do |k, v|
if k.match (/^stats/)
^----- extra space.
OK
Thanks, Weitao
Thanks, Liushaofei
Dir.mkdir("#{result_root}/stats") unless File.exists?("#{result_root}/stats")
File.open("#{result_root}/#{k}", "w+", File::Permissions.new(0o775)) do |file|
file.puts v
end
end
- end
- end
end
2.23.0