-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deferred retry of hardware_info handling when device not found
Since we deployed the devices refactor, a slightly subtle bug has emerged: if a device sends the hardware_info packet before the user has completed registration, the device is not found, the info is not saved, and therefore the device information in the UI is incomplete. This (hopefully, I like to test on staging with a real device) fixes this by relying on Sidekiq's built in error handling functionality to retry the hardware_info message (with backoff) in the event that no device corresponds to the given key. Sidekiq defaults to 25 retries with backoff (corresponding to about 3 weeks of elapsed time between the first and the last try), which should be sufficient: https://docs.gitlab.com/ee/development/sidekiq/.
- Loading branch information
1 parent
9dafc70
commit 736ad61
Showing
4 changed files
with
55 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class RetryMQTTMessageJob < ApplicationJob | ||
queue_as :default | ||
|
||
def perform(topic, message) | ||
result = MqttMessagesHandler.handle_topic(topic, message, false) | ||
raise "Message handler returned nil, retrying" if result.nil? | ||
end | ||
end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe RetryMQTTMessageJob, type: :job do | ||
it "retries the mqtt ingest with the given topic and message, and with automatic retries disabled" do | ||
topic = "topic/1/2/3" | ||
message = '{"foo": "bar", "test": "message"}' | ||
expect(MqttMessagesHandler).to receive(:handle_topic).with(topic, message, false).and_return(true) | ||
RetryMQTTMessageJob.perform_now(topic, message) | ||
end | ||
|
||
it "raises an error if the handler returns nil" do | ||
topic = "topic/1/2/3" | ||
message = '{"foo": "bar", "test": "message"}' | ||
expect(MqttMessagesHandler).to receive(:handle_topic).with(topic, message, false).and_return(nil) | ||
expect { | ||
RetryMQTTMessageJob.perform_now(topic, message) | ||
}.to raise_error | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters