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; elapsed is Float seconds and started_at a Time, as upstream.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arr) ⇒ ProfileRecord

arr is the HMGET of ProfileSet::METADATA_FIELDS, in that order.



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

def initialize(arr)
  @started_at = ::Time.at(Integer(arr[0]))
  @jid = arr[1]
  @type = arr[2]
  @token = arr[3]
  @size = Integer(arr[4])
  @elapsed = Float(arr[5])
end

Instance Attribute Details

#elapsed ⇒ Object (readonly)

Returns the value of attribute elapsed.



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

def elapsed
  @elapsed
end

#jid ⇒ Object (readonly)

Returns the value of attribute jid.



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

def jid
  @jid
end

#size ⇒ Object (readonly)

Returns the value of attribute size.



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

def size
  @size
end

#started_at ⇒ Object (readonly)

Returns the value of attribute started_at.



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

def started_at
  @started_at
end

#token ⇒ Object (readonly)

Returns the value of attribute token.



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

def token
  @token
end

#type ⇒ Object (readonly)

Returns the value of attribute type.



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

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.



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

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

Instance Method Details

#data ⇒ Object

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.



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

def data
  self.class.data_for(key)
end

#key ⇒ Object



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

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