peak_flow_utils 0.1.16 → 0.1.17
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 +4 -4
- data/README.md +12 -0
- data/app/services/peak_flow_utils/active_job_parameters_logging.rb +13 -0
- data/app/services/peak_flow_utils/sidekiq_parameters_logging.rb +16 -0
- data/lib/peak_flow_utils/notifier.rb +11 -0
- data/lib/peak_flow_utils/version.rb +1 -1
- data/lib/peak_flow_utils.rb +5 -2
- metadata +4 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 3917057ab2d29651eec619ccb60c5a6c671ce092ada22ff80269ce399a8a7bd6
         | 
| 4 | 
            +
              data.tar.gz: 25738f4241971584cfbbc9ea80cbf07f426c5dac8b6394398eb92212c8818be1
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 144f08cb6bb1af54806406e1a9ce16ade04bea01e07cf8c16537764236f9e58d672956a9346ddc6a5088f1ed8e8a3c87ff8d02ff797f230b74e47fa685590005
         | 
| 7 | 
            +
              data.tar.gz: 324f5e6834f219cb4a51dd2c3a1df5321f4912e6586ea9a67c90d05554aeae231466b7da5dd23148cef8426aae93dc02862c91faf56c58a7fa1a1125c01b9e61
         | 
    
        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,11 @@ 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 | 
            +
             | 
| 49 61 | 
             
            ## Contributing
         | 
| 50 62 | 
             
            Contribution directions go here.
         | 
| 51 63 |  | 
| @@ -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
         | 
    
        data/lib/peak_flow_utils.rb
    CHANGED
    
    | @@ -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. | 
| 4 | 
            +
              version: 0.1.17
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - kaspernj
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2022- | 
| 11 | 
            +
            date: 2022-04-27 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
         |