class MerrittZK::LegacyItem
Base class for Legacy Merritt ZooKeeper Queue Items. This class will be removed after the migration is successfully completed
Constants
- DIR
- STATUS_VALS
Attributes
id[R]
Public Class Methods
new(id)
click to toggle source
# File lib/merritt_zk_queue_item.rb, line 168 def initialize(id) @id = id @data = {} @bytes = [] @payload = {} end
Public Instance Methods
dir()
click to toggle source
# File lib/merritt_zk_queue_item.rb, line 156 def dir DIR end
json?()
click to toggle source
# File lib/merritt_zk_queue_item.rb, line 194 def json? true end
load(zk)
click to toggle source
# File lib/merritt_zk_queue_item.rb, line 175 def load(zk) arr = zk.get("#{dir}/#{@id}") return if arr.nil? payload = arr[0] @bytes = payload.nil? ? [] : payload.bytes @payload = payload_object end
path()
click to toggle source
# File lib/merritt_zk_queue_item.rb, line 160 def path "#{dir}/#{id}" end
payload_object()
click to toggle source
# File lib/merritt_zk_queue_item.rb, line 212 def payload_object json = { payload: payload_text } json = JSON.parse(payload_text, symbolize_names: true) if json? json[:queueNode] = dir json[:id] = @id json[:date] = time.to_s json[:status] = status_name json[:path] = path json end
payload_text()
click to toggle source
# File lib/merritt_zk_queue_item.rb, line 206 def payload_text return '' if @bytes.length < 10 @bytes[9..].pack('c*') end
status_byte()
click to toggle source
# File lib/merritt_zk_queue_item.rb, line 184 def status_byte @bytes.empty? ? 0 : @bytes[0] end
status_name()
click to toggle source
# File lib/merritt_zk_queue_item.rb, line 188 def status_name return 'NA' if status_byte > status_vals.length status_vals[status_byte] end
status_vals()
click to toggle source
# File lib/merritt_zk_queue_item.rb, line 164 def status_vals STATUS_VALS end
time()
click to toggle source
# File lib/merritt_zk_queue_item.rb, line 198 def time return nil if @bytes.length < 9 # https://stackoverflow.com/a/68855488/3846548 t = @bytes[1..8].inject(0) { |m, b| (m << 8) + b } Time.at(t / 1000) end