Module: WorkerTools::RocketchatErrorNotifier
- Defined in:
- lib/worker_tools/rocketchat_error_notifier.rb
Instance Method Summary collapse
- #rocketchat_error_notifier_attachment(error) ⇒ Object
- #rocketchat_error_notifier_emoji ⇒ Object
- #rocketchat_error_notifier_enabled ⇒ Object
- #rocketchat_error_notifier_error_details(error) ⇒ Object
- #rocketchat_error_notifier_event ⇒ Object
- #rocketchat_error_notifier_message ⇒ Object
- #rocketchat_error_notifier_receivers ⇒ Object
- #rocketchat_error_notifier_title ⇒ Object
- #rocketchat_error_notify(error) ⇒ Object
- #with_wrapper_rocketchat_error_notifier(&block) ⇒ Object
Instance Method Details
#rocketchat_error_notifier_attachment(error) ⇒ Object
55 56 57 |
# File 'lib/worker_tools/rocketchat_error_notifier.rb', line 55 def (error) { collapsed: true, title: 'Error', text: rocketchat_error_notifier_error_details(error) } end |
#rocketchat_error_notifier_emoji ⇒ Object
14 15 16 |
# File 'lib/worker_tools/rocketchat_error_notifier.rb', line 14 def rocketchat_error_notifier_emoji ':red_circle:' end |
#rocketchat_error_notifier_enabled ⇒ Object
10 11 12 |
# File 'lib/worker_tools/rocketchat_error_notifier.rb', line 10 def rocketchat_error_notifier_enabled Rails.env.production? end |
#rocketchat_error_notifier_error_details(error) ⇒ Object
43 44 45 46 |
# File 'lib/worker_tools/rocketchat_error_notifier.rb', line 43 def rocketchat_error_notifier_error_details(error) details = "#{error.class}: #{error.message}\n" details << error.backtrace[0..10].join("\n") end |
#rocketchat_error_notifier_event ⇒ Object
22 23 24 |
# File 'lib/worker_tools/rocketchat_error_notifier.rb', line 22 def rocketchat_error_notifier_event 'Worker Error Notifier' end |
#rocketchat_error_notifier_message ⇒ Object
48 49 50 51 52 53 |
# File 'lib/worker_tools/rocketchat_error_notifier.rb', line 48 def = [] << rocketchat_error_notifier_receivers << rocketchat_error_notifier_title .compact.join(' - ') end |
#rocketchat_error_notifier_receivers ⇒ Object
18 19 20 |
# File 'lib/worker_tools/rocketchat_error_notifier.rb', line 18 def rocketchat_error_notifier_receivers # Ex: '@all' end |
#rocketchat_error_notifier_title ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/worker_tools/rocketchat_error_notifier.rb', line 26 def rocketchat_error_notifier_title # Example with a link: # # For urls a default_url_options[:host] might be necessary. # In this example I just copy it from existing action_mailer defaults. # # import = rocketchat_error_notifier_model # host = Rails.application.config.action_mailer.default_url_options[:host] # url = Rails.application.routes.url_helpers.import_url(import, host: host, protocol: :https) # kind = I18n.t(import.kind, scope: 'import.kinds') # text = "##{import.id} *#{kind}*" # "[#{text}](#{url})" klass = model.class.model_name.human kind = I18n.t("activerecord.attributes.#{model.class.name.underscore}.kinds.#{model.kind}") "#{klass} #{kind} ##{model.id}" end |
#rocketchat_error_notify(error) ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'lib/worker_tools/rocketchat_error_notifier.rb', line 59 def rocketchat_error_notify(error) RocketChatNotifier.notify( , emoji: rocketchat_error_notifier_emoji, event: "#{rocketchat_error_notifier_event} (#{Rails.env})", attachment: (error) ) end |
#with_wrapper_rocketchat_error_notifier(&block) ⇒ Object
3 4 5 6 7 8 |
# File 'lib/worker_tools/rocketchat_error_notifier.rb', line 3 def with_wrapper_rocketchat_error_notifier(&block) block.yield rescue StandardError => e rocketchat_error_notify(e) if rocketchat_error_notifier_enabled raise end |