Class: Wurk::ProfileRecord

Inherits:
Object
  • Object
show all
Defined in:
lib/wurk/profile_set.rb

Overview

One profile record: the metadata fields of a ‘<token>-<jid>` HASH plus lazy access to the gzipped gecko blob. Spec §19.8.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ ProfileRecord

Returns a new instance of ProfileRecord.



42
43
44
45
46
47
48
49
# File 'lib/wurk/profile_set.rb', line 42

def initialize(hash)
  @hash = hash
  @jid = hash['jid']
  @type = hash['type']
  @token = hash['token']
  @size = hash['size'].to_i
  @elapsed = hash['elapsed'].to_i
end

Instance Attribute Details

#elapsedObject (readonly)

Returns the value of attribute elapsed.



40
41
42
# File 'lib/wurk/profile_set.rb', line 40

def elapsed
  @elapsed
end

#jidObject (readonly)

Returns the value of attribute jid.



40
41
42
# File 'lib/wurk/profile_set.rb', line 40

def jid
  @jid
end

#sizeObject (readonly)

Returns the value of attribute size.



40
41
42
# File 'lib/wurk/profile_set.rb', line 40

def size
  @size
end

#tokenObject (readonly)

Returns the value of attribute token.



40
41
42
# File 'lib/wurk/profile_set.rb', line 40

def token
  @token
end

#typeObject (readonly)

Returns the value of attribute type.



40
41
42
# File 'lib/wurk/profile_set.rb', line 40

def type
  @type
end

Instance Method Details

#dataObject

The stored blob is gzipped gecko JSON. ‘data` returns the raw (gzipped) bytes — the web layer streams them straight to the browser with a gzip Content-Encoding. Returns nil if the HASH expired between list and read.



61
62
63
# File 'lib/wurk/profile_set.rb', line 61

def data
  Wurk.redis { |conn| conn.call('HGET', key, 'data') }
end

#keyObject



56
# File 'lib/wurk/profile_set.rb', line 56

def key = Wurk::Profiler.profile_key(@token, @jid)

#started_atObject



51
52
53
54
# File 'lib/wurk/profile_set.rb', line 51

def started_at
  ts = @hash['started_at']
  ::Time.at(ts.to_i) unless ts.nil? || ts.empty?
end