From b7bb3a51f31eaf87786eea72645eb845206dde01 Mon Sep 17 00:00:00 2001 From: Tim Cowlishaw Date: Thu, 26 Oct 2023 14:56:16 +0200 Subject: [PATCH] set sentry scopes properly in rake tasks --- lib/tasks/mqtt_subscriber.rake | 12 ++++++++---- lib/tasks/telnet.rake | 12 +++++++----- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/lib/tasks/mqtt_subscriber.rake b/lib/tasks/mqtt_subscriber.rake index 6b432a9b..9952eae3 100644 --- a/lib/tasks/mqtt_subscriber.rake +++ b/lib/tasks/mqtt_subscriber.rake @@ -38,10 +38,14 @@ namespace :mqtt do ) client.get do |topic, message| - MqttMessagesHandler.handle_topic(topic, message) - rescue Exception => e - mqtt_log.info e - Sentry.capture_exception(e) + Sentry.with_scope do + begin + MqttMessagesHandler.handle_topic(topic, message) + rescue Exception => e + mqtt_log.info e + Sentry.capture_exception(e) + end + end end end rescue SystemExit, Interrupt, SignalException diff --git a/lib/tasks/telnet.rake b/lib/tasks/telnet.rake index d7d74ea5..98c80e5b 100644 --- a/lib/tasks/telnet.rake +++ b/lib/tasks/telnet.rake @@ -20,12 +20,14 @@ namespace :telnet do p 'Starting Redis subscription...' Redis.current.subscribe('telnet_queue') do |on| on.message do |channel, msg| - #puts "#{channel} - #{msg}" - alldata = JSON.parse(msg) + Sentry.with_scope do + #puts "#{channel} - #{msg}" + alldata = JSON.parse(msg) - alldata.each do |data| - telnet_string = "put #{data['name']} #{data['timestamp']} #{data['value']} device_id=#{data['tags']['device_id']} \n" - localhost.print telnet_string + alldata.each do |data| + telnet_string = "put #{data['name']} #{data['timestamp']} #{data['value']} device_id=#{data['tags']['device_id']} \n" + localhost.print telnet_string + end end end end