peak_flow_utils 0.1.16 → 0.1.18

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c01a814a1aad134f668f7144f6addea59f8b8afdc75a2ae8ff2280dbe3a9867c
4
- data.tar.gz: b6746741a1ff204c7b2a31319409d84a4529c14a55f8e9cfbf7b7fcad37eacea
3
+ metadata.gz: 1d6ad793f87d038dc928420a3c35e046fa1fcfb4f610e4fd6bd1c9f8fa445a9e
4
+ data.tar.gz: 9abdb774bfa6fd91896dfdbe55b6d6d7e931804035712aa51e1c576ab9d4d6cf
5
5
  SHA512:
6
- metadata.gz: 5a82e952b87453cfde4fbcb42fd43a0f2bca93f43dc2b3dbdca3109c6d25a21dd587745c602680d89c446cda1c1be251167b46248b98bc1e5354f408ae9f2758
7
- data.tar.gz: d2020073122505feaa6cb3923f79a76ff6f8608ac45af16625cae83f79c6232a9f4ac677e834faa015bfd1d9e287946b4cc0662557507dcfab89ea7c3faf665e
6
+ metadata.gz: ef054a48493eb11175e79cfdac7b9c2ae5258c8d67c3113bb0c61633404df7c6b674dc2fda6809a3c0ded02533f7fe88407bc4b8693a6c982d772f84a1f2de51
7
+ data.tar.gz: 6b4cd15ee4e07feabc1e0c4b6bb9efc59aff36dad76c8fae97ff9f8d1d486dc570ae5e69997f872105dffc6036e167beb00e0995b5b115561964facc12b63da2
data/README.md CHANGED
@@ -39,6 +39,13 @@ Add this to `config/peakflow.rb`:
39
39
  PeakFlowUtils::NotifierRails.configure
40
40
  ```
41
41
 
42
+ ### Reporting ActiveJob errors in Rails:
43
+
44
+ If you want the job name and its arguments logged in parameters you can execute this service:
45
+ ```ruby
46
+ PeakFlowUtils::ActiveJobParametersLogging.execute!
47
+ ```
48
+
42
49
  ### Reporting Sidekiq errors in Rails:
43
50
 
44
51
  Add this to `config/peakflow.rb`:
@@ -46,6 +53,31 @@ Add this to `config/peakflow.rb`:
46
53
  PeakFlowUtils::NotifierSidekiq.configure
47
54
  ```
48
55
 
56
+ If you want the job name and its arguments logged in parameters you can execute this service:
57
+ ```ruby
58
+ PeakFlowUtils::SidekiqParametersLogging.execute!
59
+ ```
60
+
61
+ ### Sidekiq and Postgres pings
62
+
63
+ Add this to `routes.rb`:
64
+ ```ruby
65
+ Rails.application.routes.draw do
66
+ mount PeakFlowUtils::Engine => "/peakflow_utils"
67
+ ```
68
+
69
+ Add these to .env variables:
70
+ ```
71
+ PEAKFLOW_PINGS_USERNAME=username
72
+ PEAKFLOW_PINGS_PASSWORD=secret-password
73
+ ```
74
+
75
+ You can now add a HTTP ping on this path:
76
+ `/peakflow_utils/pings/sidekiq`
77
+
78
+ And this for Postgres:
79
+ `/pings/postgres_connections`
80
+
49
81
  ## Contributing
50
82
  Contribution directions go here.
51
83
 
@@ -9,7 +9,7 @@ private
9
9
  authenticate_or_request_with_http_basic do |username, password|
10
10
  if ENV["PEAKFLOW_PINGS_USERNAME"].blank? || ENV["PEAKFLOW_PINGS_PASSWORD"].blank?
11
11
  Rails.logger.error "Peakflow utils: Pings called but PEAKFLOW_PINGS_USERNAME or PEAKFLOW_PINGS_PASSWORD wasn't set"
12
- false
12
+ return false
13
13
  end
14
14
 
15
15
  username == ENV.fetch("PEAKFLOW_PINGS_USERNAME") && password == ENV.fetch("PEAKFLOW_PINGS_PASSWORD")
@@ -1,7 +1,6 @@
1
- require "sidekiq/api"
2
-
3
1
  class PeakFlowUtils::Pings::SidekiqController < PeakFlowUtils::ApplicationController
4
2
  def index
3
+ require "sidekiq/api"
5
4
  sidekiq_queue = Sidekiq::Queue.new
6
5
 
7
6
  render json: {
@@ -0,0 +1,13 @@
1
+ class PeakFlowUtils::ActiveJobParametersLogging < PeakFlowUtils::ApplicationService
2
+ def perform
3
+ ActiveJob::Base.class_eval do
4
+ around_perform do |job, block|
5
+ PeakFlowUtils::Notifier.with_parameters(active_job: {job_name: job.class.name, job_arguments: job.arguments}) do
6
+ block.call
7
+ end
8
+ end
9
+ end
10
+
11
+ succeed!
12
+ end
13
+ end
@@ -0,0 +1,16 @@
1
+ class PeakFlowUtils::SidekiqParametersLogging < PeakFlowUtils::ApplicationService
2
+ def perform
3
+ require "sidekiq"
4
+ require "sidekiq/processor"
5
+
6
+ Sidekiq::Processor.class_eval do
7
+ def execute_job(worker, cloned_args)
8
+ PeakFlowUtils::Notifier.with_parameters(sidekiq: {worker_class_name: worker.class.name, cloned_args: cloned_args}) do
9
+ worker.perform(*cloned_args)
10
+ end
11
+ end
12
+ end
13
+
14
+ succeed!
15
+ end
16
+ end
@@ -1,6 +1,7 @@
1
1
  class PeakFlowUtils::Notifier
2
2
  class FailedToReportError < RuntimeError; end
3
3
  class NotConfiguredError < RuntimeError; end
4
+ class NotifyMessageError < RuntimeError; end
4
5
 
5
6
  attr_reader :auth_token, :mutex, :parameters
6
7
 
@@ -16,6 +17,10 @@ class PeakFlowUtils::Notifier
16
17
  PeakFlowUtils::Notifier.current&.notify(*args, **opts, &blk)
17
18
  end
18
19
 
20
+ def self.notify_message(*args, **opts, &blk)
21
+ PeakFlowUtils::Notifier.current&.notify_message(*args, **opts, &blk)
22
+ end
23
+
19
24
  def self.reset_parameters
20
25
  ::PeakFlowUtils::Notifier.current&.instance_variable_set(:@parameters, ::PeakFlowUtils::InheritedLocalVar.new({}))
21
26
  end
@@ -104,6 +109,12 @@ class PeakFlowUtils::Notifier
104
109
  send_notify_request(data: data, uri: uri)
105
110
  end
106
111
 
112
+ def notify_message(message, **opts)
113
+ raise NotifyMessageError, message
114
+ rescue NotifyMessageError => e
115
+ notify(error: e, **opts)
116
+ end
117
+
107
118
  def send_notify_request(data:, uri:)
108
119
  https = ::Net::HTTP.new(uri.host, uri.port)
109
120
  https.use_ssl = true
@@ -1,3 +1,3 @@
1
1
  module PeakFlowUtils
2
- VERSION = "0.1.16".freeze
2
+ VERSION = "0.1.18".freeze
3
3
  end
@@ -8,8 +8,6 @@ module PeakFlowUtils
8
8
  models_path = "#{__dir__}/peak_flow_utils/models"
9
9
  services_path = File.realpath("#{__dir__}/../app/services/peak_flow_utils")
10
10
 
11
- autoload :ApplicationService, "#{services_path}/application_service"
12
- autoload :DeepMerger, "#{services_path}/deep_merger"
13
11
  autoload :InheritedLocalVar, "#{path}/inherited_local_var"
14
12
  autoload :Notifier, "#{path}/notifier"
15
13
  autoload :NotifierErrorParser, "#{path}/notifier_error_parser"
@@ -26,4 +24,9 @@ module PeakFlowUtils
26
24
  autoload :ScannedFile, "#{models_path}/scanned_file"
27
25
  autoload :TranslationKey, "#{models_path}/translation_key"
28
26
  autoload :TranslationValue, "#{models_path}/translation_value"
27
+
28
+ autoload :ActiveJobParametersLogging, "#{services_path}/active_job_parameters_logging"
29
+ autoload :ApplicationService, "#{services_path}/application_service"
30
+ autoload :SidekiqParametersLogging, "#{services_path}/sidekiq_parameters_logging"
31
+ autoload :DeepMerger, "#{services_path}/deep_merger"
29
32
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: peak_flow_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.16
4
+ version: 0.1.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - kaspernj
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-02-22 00:00:00.000000000 Z
11
+ date: 2023-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -157,6 +157,7 @@ files:
157
157
  - app/handlers/peak_flow_utils/simple_form_handler.rb
158
158
  - app/handlers/peak_flow_utils/validations_handler.rb
159
159
  - app/handlers/peak_flow_utils/will_paginate_handler.rb
160
+ - app/services/peak_flow_utils/active_job_parameters_logging.rb
160
161
  - app/services/peak_flow_utils/application_migration.rb
161
162
  - app/services/peak_flow_utils/application_service.rb
162
163
  - app/services/peak_flow_utils/attribute_service.rb
@@ -169,6 +170,7 @@ files:
169
170
  - app/services/peak_flow_utils/group_service.rb
170
171
  - app/services/peak_flow_utils/handlers_finder_service.rb
171
172
  - app/services/peak_flow_utils/model_inspector.rb
173
+ - app/services/peak_flow_utils/sidekiq_parameters_logging.rb
172
174
  - app/services/peak_flow_utils/translation_service.rb
173
175
  - app/services/peak_flow_utils/translations_parser_service.rb
174
176
  - config/routes.rb