peak_flow_utils 0.1.17 → 0.1.19

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3917057ab2d29651eec619ccb60c5a6c671ce092ada22ff80269ce399a8a7bd6
4
- data.tar.gz: 25738f4241971584cfbbc9ea80cbf07f426c5dac8b6394398eb92212c8818be1
3
+ metadata.gz: bbb8a48ea294481df8df3c87b5b17eca7c7b2715027a512655f66a318acb8e2e
4
+ data.tar.gz: 1970d5b4843db5df6396e12d6cacfa70049af0ac8946f4e7243d3a7f70b5d981
5
5
  SHA512:
6
- metadata.gz: 144f08cb6bb1af54806406e1a9ce16ade04bea01e07cf8c16537764236f9e58d672956a9346ddc6a5088f1ed8e8a3c87ff8d02ff797f230b74e47fa685590005
7
- data.tar.gz: 324f5e6834f219cb4a51dd2c3a1df5321f4912e6586ea9a67c90d05554aeae231466b7da5dd23148cef8426aae93dc02862c91faf56c58a7fa1a1125c01b9e61
6
+ metadata.gz: d1866c116955f38e9f2dc3c2e06fbeca908ed4c0bb425348a82fa8f1522fcfb1e47d1c96fe1a32328bd44f439f26dfddb97285dd0c19b0725f5241dcdb671d51
7
+ data.tar.gz: ac9fa1d930c30b5d32d450b10bd2af6ec95ead713b64e686ab07de7cbec5db94e5b4048e0a16e13657d06f1d483a5d4252d1c3d4068e188cfcd4586cc55a1349
data/README.md CHANGED
@@ -58,6 +58,26 @@ If you want the job name and its arguments logged in parameters you can execute
58
58
  PeakFlowUtils::SidekiqParametersLogging.execute!
59
59
  ```
60
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
+
61
81
  ## Contributing
62
82
  Contribution directions go here.
63
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,39 @@
1
+ class PeakFlowUtils::ParseJson
2
+ def initialize(object)
3
+ @object = object
4
+ end
5
+
6
+ def parse
7
+ parse_to_json(@object)
8
+ end
9
+
10
+ def active_record?(object)
11
+ object.class.ancestors.any? do |ancestor|
12
+ ancestor.name == "ActiveRecord::Base"
13
+ end
14
+ end
15
+
16
+ def parse_to_json(object)
17
+ if object.is_a?(Hash)
18
+ result = {}
19
+
20
+ object.each do |key, value|
21
+ result[key] = parse_to_json(value)
22
+ end
23
+
24
+ return result
25
+ elsif object.is_a?(Array)
26
+ return object.map do |value|
27
+ parse_to_json(value)
28
+ end
29
+ elsif active_record?(object)
30
+ result = "#<#{object.class.name} id: #{object.id}"
31
+ result << " name: \"#{object.name}\"" if object.respond_to?(:name)
32
+ result << ">"
33
+
34
+ return result
35
+ end
36
+
37
+ object
38
+ end
39
+ end
@@ -106,7 +106,7 @@ class PeakFlowUtils::Notifier
106
106
  }
107
107
  }
108
108
 
109
- send_notify_request(data: data, uri: uri)
109
+ send_notify_request(data: PeakFlowUtils::ParseJson.new(data).parse, uri: uri)
110
110
  end
111
111
 
112
112
  def notify_message(message, **opts)
@@ -1,3 +1,3 @@
1
1
  module PeakFlowUtils
2
- VERSION = "0.1.17".freeze
2
+ VERSION = "0.1.19".freeze
3
3
  end
@@ -16,6 +16,7 @@ module PeakFlowUtils
16
16
  autoload :NotifierResponse, "#{path}/notifier_response"
17
17
  autoload :NotifierSidekiq, "#{path}/notifier_sidekiq"
18
18
  autoload :HandlerHelper, "#{path}/handler_helper"
19
+ autoload :ParseJson, "#{path}/parse_json"
19
20
 
20
21
  autoload :ApplicationRecord, "#{models_path}/application_record"
21
22
  autoload :Group, "#{models_path}/group"
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.17
4
+ version: 0.1.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - kaspernj
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-27 00:00:00.000000000 Z
11
+ date: 2024-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -138,7 +138,7 @@ dependencies:
138
138
  version: '0'
139
139
  description: Utilities to be used with PeakFlow.
140
140
  email:
141
- - kaspernj@gmail.com
141
+ - k@spernj.org
142
142
  executables: []
143
143
  extensions: []
144
144
  extra_rdoc_files: []
@@ -170,6 +170,7 @@ files:
170
170
  - app/services/peak_flow_utils/group_service.rb
171
171
  - app/services/peak_flow_utils/handlers_finder_service.rb
172
172
  - app/services/peak_flow_utils/model_inspector.rb
173
+ - app/services/peak_flow_utils/parse_json.rb
173
174
  - app/services/peak_flow_utils/sidekiq_parameters_logging.rb
174
175
  - app/services/peak_flow_utils/translation_service.rb
175
176
  - app/services/peak_flow_utils/translations_parser_service.rb
@@ -219,7 +220,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
219
220
  - !ruby/object:Gem::Version
220
221
  version: '0'
221
222
  requirements: []
222
- rubygems_version: 3.2.32
223
+ rubygems_version: 3.5.3
223
224
  signing_key:
224
225
  specification_version: 4
225
226
  summary: Utilities to be used with PeakFlow.