worker_tools 0.1.2 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,68 +0,0 @@
1
- module WorkerTools
2
- module RocketchatErrorNotifier
3
- def with_wrapper_rocketchat_error_notifier(&block)
4
- block.yield
5
- rescue StandardError => e
6
- rocketchat_error_notify(e) if rocketchat_error_notifier_enabled
7
- raise
8
- end
9
-
10
- def rocketchat_error_notifier_enabled
11
- Rails.env.production?
12
- end
13
-
14
- def rocketchat_error_notifier_emoji
15
- ':red_circle:'
16
- end
17
-
18
- def rocketchat_error_notifier_receivers
19
- # Ex: '@all'
20
- end
21
-
22
- def rocketchat_error_notifier_event
23
- 'Worker Error Notifier'
24
- end
25
-
26
- def rocketchat_error_notifier_title
27
- # Example with a link:
28
- #
29
- # For urls a default_url_options[:host] might be necessary.
30
- # In this example I just copy it from existing action_mailer defaults.
31
- #
32
- # import = rocketchat_error_notifier_model
33
- # host = Rails.application.config.action_mailer.default_url_options[:host]
34
- # url = Rails.application.routes.url_helpers.import_url(import, host: host, protocol: :https)
35
- # kind = I18n.t(import.kind, scope: 'import.kinds')
36
- # text = "##{import.id} *#{kind}*"
37
- # "[#{text}](#{url})"
38
- klass = model.class.model_name.human
39
- kind = I18n.t("activerecord.attributes.#{model.class.name.underscore}.kinds.#{model.kind}")
40
- "#{klass} #{kind} ##{model.id}"
41
- end
42
-
43
- def rocketchat_error_notifier_error_details(error)
44
- details = "#{error.class}: #{error.message}\n"
45
- details << error.backtrace[0..10].join("\n")
46
- end
47
-
48
- def rocketchat_error_notifier_message
49
- message = []
50
- message << rocketchat_error_notifier_receivers
51
- message << rocketchat_error_notifier_title
52
- message.compact.join(' - ')
53
- end
54
-
55
- def rocketchat_error_notifier_attachment(error)
56
- { collapsed: true, title: 'Error', text: rocketchat_error_notifier_error_details(error) }
57
- end
58
-
59
- def rocketchat_error_notify(error)
60
- RocketChatNotifier.notify(
61
- rocketchat_error_notifier_message,
62
- emoji: rocketchat_error_notifier_emoji,
63
- event: "#{rocketchat_error_notifier_event} (#{Rails.env})",
64
- attachment: rocketchat_error_notifier_attachment(error)
65
- )
66
- end
67
- end
68
- end