lib/influxdb/rails/middleware/active_job_subscriber.rb in influxdb-rails-1.0.1.beta2 vs lib/influxdb/rails/middleware/active_job_subscriber.rb in influxdb-rails-1.0.1.beta3

- old
+ new

@@ -4,10 +4,17 @@ module Rails module Middleware class ActiveJobSubscriber < Subscriber # :nodoc: private + JOB_STATE = { + "enqueue" => "queued", + "perform_start" => "running", + "perform" => "succeeded", + }.freeze + private_constant :JOB_STATE + def values { value: value, } end @@ -22,18 +29,11 @@ end def job_state return "failed" if failed? - case short_hook_name - when "enqueue" - "queued" - when "perform_start" - "running" - when "perform" - "succeeded" - end + JOB_STATE[short_hook_name] end def measure_performance? short_hook_name == "perform" end @@ -42,12 +42,12 @@ @short_hook_name ||= fetch_short_hook_name end def fetch_short_hook_name return "enqueue" if hook_name.include?("enqueue") - return "perform_start" if hook_name.include?("perform_start") - return "perform" if hook_name.include?("perform") + + "perform" end def job @job ||= payload[:job] end @@ -57,10 +57,10 @@ 1 end def failed? - payload[:exception_object] + payload[:aborted] end end end end end