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.
- checksums.yaml +5 -5
- data/.travis.yml +2 -1
- data/CHANGELOG.md +48 -0
- data/README.md +358 -20
- data/lib/worker_tools/basics.rb +27 -11
- data/lib/worker_tools/benchmark.rb +15 -0
- data/lib/worker_tools/counters.rb +40 -0
- data/lib/worker_tools/csv_input.rb +13 -4
- data/lib/worker_tools/csv_output.rb +19 -33
- data/lib/worker_tools/errors.rb +10 -0
- data/lib/worker_tools/recorder.rb +20 -12
- data/lib/worker_tools/slack_error_notifier.rb +6 -2
- data/lib/worker_tools/utils/hash_with_indifferent_access_type.rb +9 -0
- data/lib/worker_tools/utils/serialized_array_type.rb +19 -0
- data/lib/worker_tools/version.rb +1 -1
- data/lib/worker_tools/xlsx_input.rb +14 -4
- data/lib/worker_tools/xlsx_output.rb +51 -43
- data/lib/worker_tools.rb +1 -1
- data/worker_tools.gemspec +3 -3
- metadata +15 -25
- data/lib/worker_tools/rocketchat_error_notifier.rb +0 -68
|
@@ -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
|