Module: SidekiqUniqueJobs::Timing

Included in:
Lock, Locksmith, OnConflict::Reject, OnConflict::Strategy, Orphans::RubyReaper, Redis::Entity
Defined in:
lib/sidekiq_unique_jobs/timing.rb

Overview

Handles timing of things

Author:

Class Method Summary collapse

Class Method Details

.clock_stampFloat

Returns a float representation of the current time.

Either from Process or Time

Returns:

  • (Float)


50
51
52
53
54
55
56
# File 'lib/sidekiq_unique_jobs/timing.rb', line 50

def clock_stamp
  if Process.const_defined?(:CLOCK_MONOTONIC)
    Process.clock_gettime(Process::CLOCK_MONOTONIC)
  else
    now_f
  end
end

.now_fFloat

Returns the current time as float

Returns:

  • (Float)

See Also:



39
40
41
# File 'lib/sidekiq_unique_jobs/timing.rb', line 39

def now_f
  SidekiqUniqueJobs.now_f
end

.time_sourceInteger

Used to get a current representation of time as Integer

Returns:

  • (Integer)


28
29
30
# File 'lib/sidekiq_unique_jobs/timing.rb', line 28

def time_source
  -> { (clock_stamp * 1000).to_i }
end

.timedyield return, Float

Used for timing method calls

Returns:

  • (yield return, Float)


16
17
18
19
20
# File 'lib/sidekiq_unique_jobs/timing.rb', line 16

def timed
  start_time = time_source.call

  [yield, time_source.call - start_time]
end