Skip to content

Commit

Permalink
ensure hardware_info and check jobs dont update device updated_at
Browse files Browse the repository at this point in the history
  • Loading branch information
timcowlishaw committed Jan 9, 2024
1 parent d596dd6 commit acccc20
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/jobs/check_battery_level_below_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def perform(*args)
if device.data["10"].to_i < 15 && device.data["10"].to_i > 1
#p "Sending email to: #{device.owner.email} - device: #{device}"

device.update(notify_low_battery_timestamp: Time.now)
device.update_column(:notify_low_battery_timestamp, Time.now)

UserMailer.device_battery_low(device.id).deliver_now
end
Expand Down
2 changes: 1 addition & 1 deletion app/jobs/check_device_stopped_publishing_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def perform(*args)

devices.each do |device|
if device.notify_stopped_publishing_timestamp < 24.hours.ago
device.update notify_stopped_publishing_timestamp: Time.now
device.update_column(:notify_stopped_publishing_timestamp, Time.now)
UserMailer.device_stopped_publishing(device.id).deliver_now
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/lib/mqtt_messages_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def self.handle_topic(topic, message)
}
)
Sentry.add_breadcrumb(crumb)
device.update hardware_info: json_message
device.update_column(:hardware_info, json_message)
end
end

Expand Down
7 changes: 4 additions & 3 deletions spec/jobs/check_battery_level_below_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
RSpec.describe CheckBatteryLevelBelowJob, type: :job do

it 'should update notify_low_battery_timestamp and send email' do
device = create(:device, notify_low_battery: true)

device = create(:device, notify_low_battery: true, updated_at: "2023-01-01 00:00:00")
updated_at_before = device.updated_at
time_before = device.notify_low_battery_timestamp
device.update(data: { "10": '11'})
device.update_columns(data: { "10": '11'})

expect(device.data["10"].to_i).to eq(11)

CheckBatteryLevelBelowJob.perform_now

device.reload
expect(time_before).not_to eq(device.notify_low_battery_timestamp)
expect(device.updated_at).to eq(updated_at_before)
end
end

0 comments on commit acccc20

Please sign in to comment.