Sha256: c0acc660de5540ec0246806de049b1c2ea837187ec3ce8e7cd65dac4f54110af

Contents?: true

Size: 662 Bytes

Versions: 1

Compression:

Stored size: 662 Bytes

Contents

module QPush
  module Server
    module Apis
      class Execute < Base
        def initialize(job)
          @job = job
        end

        def call
          measure_run_time { job_object.call }
          Success.call(@job)
        rescue => e
          Fail.call(@job, e)
        end

        private

        def measure_run_time
          start = Time.now
          yield
          finish = Time.now
          @job.run_time = "#{((finish - start) * 1000.0).round(3)} ms"
        end

        def job_object
          klass = Object.const_get(@job.klass)
          @job.args.empty? ? klass.new : klass.new(@job.args)
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
qpush-0.1.4 lib/qpush/server/apis/execute.rb