Skip to content

Commit

Permalink
queue data packets for unknown devices for retry
Browse files Browse the repository at this point in the history
  • Loading branch information
timcowlishaw committed May 6, 2024
1 parent 1760d33 commit 77bb525
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/lib/mqtt_messages_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def self.handle_topic(topic, message, retry_on_nil_device=true)
end

def self.handle_nil_device(topic, message, retry_on_nil_device)
if topic.to_s.include?("info")
if !topic.to_s.include?("inventory")
retry_later(topic, message) if retry_on_nil_device
end
end
Expand Down
22 changes: 16 additions & 6 deletions spec/lib/mqtt_messages_handler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,24 @@
)
MqttMessagesHandler.handle_topic(@packet.topic, @hardware_info_packet.payload)
end
end

context 'invalid packet' do
it 'it notifies Sentry' do
allow(Sentry).to receive(:capture_exception)
expect(Kairos).not_to receive(:http_post_to)
it 'defers messages with unknown device tokens if retry flag is true' do
expect(RetryMQTTMessageJob).to receive(:perform_later).with(@invalid_packet.topic, @invalid_packet.payload)
MqttMessagesHandler.handle_topic(@invalid_packet.topic, @invalid_packet.payload)
#expect(Sentry).to have_received(:capture_exception).with(RuntimeError)
end

it 'does not defer messages with unknown device tokens if retry flag is false' do
expect(RetryMQTTMessageJob).not_to receive(:perform_later).with(@invalid_packet.topic, @invalid_packet.payload)
MqttMessagesHandler.handle_topic(@invalid_packet.topic, @invalid_packet.payload, false)
end

context 'invalid packet' do
it 'it notifies Sentry' do
allow(Sentry).to receive(:capture_exception)
expect(Kairos).not_to receive(:http_post_to)
MqttMessagesHandler.handle_topic(@invalid_packet.topic, @invalid_packet.payload)
#expect(Sentry).to have_received(:capture_exception).with(RuntimeError)
end
end
end
end
Expand Down

0 comments on commit 77bb525

Please sign in to comment.