is_my_sidekiq_ok 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e94d1eb329ad49eafdf8f5f6da9de711f72321bb9ecdb05baf51b0cfbebd488e
4
+ data.tar.gz: 6f7c7c5995bd098f8afb88740ad72afe7800042477187a97b91c9f355a93e9a4
5
+ SHA512:
6
+ metadata.gz: 230193c7f8417fcc7e0f9702868f40484715db1e179d97af13460e05dc99a251fd04a5e183c8d9a4107d213a59d5c93e20647d91376268e0c6b8ef95b1ba6a5e
7
+ data.tar.gz: 510a547076e52b9c6a298faf57b2b2ffd23f88ed5b07af30aa9ea6cf25fa21c18ee93dcca82ae3d7b1265d5e18fea3dc0664ff654e01bf7ec2b83b8a61d8dec1
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2021 Sampo Kuokkanen
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,60 @@
1
+ # IsMySidekiqOk
2
+
3
+ IsMySidekiqOk answers the question: is your Sidekiq ok?
4
+ Define limits, and then if Sidekiq is running within those limits, you get a :success 200 response, otherwise you get a 500 error response.
5
+ Can be used with Rails > 5.2.
6
+ *You can customize the response code.
7
+ ## Usage
8
+ How to use my plugin.
9
+
10
+ ## Installation
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'is_my_sidekiq_ok'
15
+ ```
16
+
17
+ Mount the engine to get the route (`routes.rb`):
18
+
19
+ ```ruby
20
+ mount IsMySidekiqOk::Engine => '/is_my_sidekiq_ok'
21
+ ```
22
+
23
+ And then execute:
24
+ ```bash
25
+ $ bundle
26
+ ```
27
+
28
+ Or install it yourself as:
29
+ ```bash
30
+ $ gem install is_my_sidekiq_ok
31
+ ```
32
+
33
+ And now just hit that endpoint!
34
+
35
+ Though you'll probably also want to configure the gem.
36
+ This gem has the following settings:
37
+
38
+ ```ruby
39
+ # success
40
+ setting :status_symbol, :ok
41
+ # failior
42
+ setting :error_symbol, :internal_server_error
43
+ # Sidekiq instances running, fail if below this
44
+ setting :processes_size, 4
45
+ # below values will cause check to fail if exceeded
46
+ setting :default_queue_latency, 30
47
+ setting :workers_size, 0
48
+ setting :enqueued, 50
49
+
50
+ # name and password for basic auth
51
+ setting :name
52
+ setting :password
53
+ ```
54
+
55
+
56
+ ## Contributing
57
+ Contribution directions go here.
58
+
59
+ ## License
60
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/setup'
4
+
5
+ APP_RAKEFILE = File.expand_path('test/dummy/Rakefile', __dir__)
6
+ load 'rails/tasks/engine.rake'
7
+
8
+ load 'rails/tasks/statistics.rake'
9
+
10
+ require 'bundler/gem_tasks'
11
+
12
+ require 'rake/testtask'
13
+
14
+ Rake::TestTask.new(:test) do |t|
15
+ t.libs << 'test'
16
+ t.pattern = 'test/**/*_test.rb'
17
+ t.verbose = false
18
+ end
19
+
20
+ task default: :test
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module IsMySidekiqOk
4
+ class ApplicationController < ActionController::Base
5
+ end
6
+ end
@@ -0,0 +1,29 @@
1
+ require 'sidekiq/api'
2
+
3
+ module IsMySidekiqOk
4
+ class SidekiqOkController < ApplicationController
5
+ if IsMySidekiqOk.config.name.present? &&
6
+ IsMySidekiqOk.config.password.present?
7
+ http_basic_authenticate_with name: IsMySidekiqOk.config.name,
8
+ password: IsMySidekiqOk.config.password
9
+ end
10
+
11
+ def index
12
+ if IsMySidekiqOk.ok?(sidekiq_stats)
13
+ head IsMySidekiqOk.config.status_symbol
14
+ else
15
+ head IsMySidekiqOk.config.error_symbol
16
+ end
17
+ end
18
+
19
+ def stats
20
+ render json: sidekiq_stats
21
+ end
22
+
23
+ private
24
+
25
+ def sidekiq_stats
26
+ ::Sidekiq::Stats.new.fetch_stats!
27
+ end
28
+ end
29
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ IsMySidekiqOk::Engine.routes.draw do
4
+ get '/', to: 'sidekiq_ok#index'
5
+ get '/stats', to: 'sidekiq_ok#stats'
6
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'is_my_sidekiq_ok/version'
4
+ require 'is_my_sidekiq_ok/engine'
5
+ require 'dry-configurable'
6
+
7
+ # IsMySidekiqOk checks whether Sidekiq is running and is working
8
+ # within the parameters specified in the initializer.
9
+ module IsMySidekiqOk
10
+ extend Dry::Configurable
11
+ extend self
12
+
13
+ setting :status_symbol, :ok
14
+ setting :error_symbol, :internal_server_error
15
+ setting :processes_size, 4
16
+ setting :default_queue_latency, 30
17
+ setting :workers_size, 0
18
+ setting :enqueued, 50
19
+
20
+ setting :name
21
+ setting :password
22
+
23
+ SETTINGS = %i[processes_size].freeze
24
+
25
+ # TODO refactor this
26
+ def ok?(stats)
27
+ return false if SETTINGS.any? { |setting| stats[setting] <= IsMySidekiqOk.config.send(setting) }
28
+
29
+ return false if stats[:default_queue_latency] >= IsMySidekiqOk.config.default_queue_latency
30
+
31
+ return false if stats[:enqueued] >= IsMySidekiqOk.config.enqueued
32
+
33
+ return false if stats[:workers_size] >= IsMySidekiqOk.config.enqueued
34
+
35
+ true
36
+ end
37
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module IsMySidekiqOk
4
+ class Engine < ::Rails::Engine
5
+ isolate_namespace IsMySidekiqOk
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module IsMySidekiqOk
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+ # desc "Explaining what the task does"
3
+ # task :is_my_sidekiq_ok do
4
+ # # Task goes here
5
+ # end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: is_my_sidekiq_ok
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sampo Kuokkanen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-07-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: dry-configurable
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '5.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '5.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: byebug
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Define limits and see if Sidekiq is running within those.
56
+ email:
57
+ - sampo.kuokkanen@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - MIT-LICENSE
63
+ - README.md
64
+ - Rakefile
65
+ - app/controllers/is_my_sidekiq_ok/application_controller.rb
66
+ - app/controllers/is_my_sidekiq_ok/sidekiq_ok_controller.rb
67
+ - config/routes.rb
68
+ - lib/is_my_sidekiq_ok.rb
69
+ - lib/is_my_sidekiq_ok/engine.rb
70
+ - lib/is_my_sidekiq_ok/version.rb
71
+ - lib/tasks/is_my_sidekiq_ok_tasks.rake
72
+ homepage: https://github.com/sampokuokkanen/is_my_sidekiq_ok
73
+ licenses:
74
+ - MIT
75
+ metadata:
76
+ homepage_uri: https://github.com/sampokuokkanen/is_my_sidekiq_ok
77
+ source_code_uri: https://github.com/sampokuokkanen/is_my_sidekiq_ok
78
+ changelog_uri: https://github.com/sampokuokkanen/is_my_sidekiq_ok/blob/main/CHANGELOG.md
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubygems_version: 3.2.15
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: Is your Sidekiq ok? This gem tells you.
98
+ test_files: []