Early stage log worker: Next- update procfile.

pull/554/head
Rick Carlino 2017-12-06 12:06:30 -06:00
parent 97882f8c0a
commit 4a45e1b2b2
2 changed files with 21 additions and 10 deletions

View File

@ -11,10 +11,10 @@ module Transport
end
def self.log_channel
@log_channel ||= self.connection
.create_channel
.queue("", exclusive: true)
.bind("amq.topic", routing_key: "bot.*.logs")
@log_channel ||= self.connection
.create_channel
.queue("", exclusive: true)
.bind("amq.topic", routing_key: "bot.*.logs")
end
def self.topic

View File

@ -1,6 +1,17 @@
binding.pry
loop do
puts "Ding!"
sleep 5
end
Transport
.log_channel
.subscribe(block: true) do |delivery_info, properties, payload|
# Legacy FBOS still uses the API for log storage.
headers = properties[:headers] || {}
# Guess version
not_legacy = !headers.keys.join(" ").include?("mqtt")
if (not_legacy)
# Extract current user (if version is appropriate)
device_id = delivery_info.routing_key.split(".")[1].gsub("device_", "").to_i
device = Device.find(device_id)
# Parse payload
payload = JSON.parse(payload)
puts "===== INCOMING LOG ====="
puts payload
end
end