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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ ProfileRecord

Returns a new instance of ProfileRecord.



57
58
59
60
61
62
63
64
# File 'lib/wurk/profile_set.rb', line 57

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.



47
48
49
# File 'lib/wurk/profile_set.rb', line 47

def elapsed
  @elapsed
end

#jidObject (readonly)

Returns the value of attribute jid.



47
48
49
# File 'lib/wurk/profile_set.rb', line 47

def jid
  @jid
end

#sizeObject (readonly)

Returns the value of attribute size.



47
48
49
# File 'lib/wurk/profile_set.rb', line 47

def size
  @size
end

#tokenObject (readonly)

Returns the value of attribute token.



47
48
49
# File 'lib/wurk/profile_set.rb', line 47

def token
  @token
end

#typeObject (readonly)

Returns the value of attribute type.



47
48
49
# File 'lib/wurk/profile_set.rb', line 47

def type
  @type
end

Class Method Details

.data_for(key) ⇒ Object

Fetch the stored gzipped blob for a profile storage key ("-") straight from Redis, without materializing the whole record โ€” the Profiles data endpoint streams it to the browser as-is. nil if the HASH is gone. Owns the data HASH-field name so web callers don't hardcode the schema.



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

def self.data_for(key)
  Wurk.redis { |conn| conn.call('HGET', key, 'data') }
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.



76
77
78
# File 'lib/wurk/profile_set.rb', line 76

def data
  self.class.data_for(key)
end

#keyObject



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

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

#started_atObject



66
67
68
69
# File 'lib/wurk/profile_set.rb', line 66

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