spinnaker-sidekiq 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c1227c6d8e7b04dde5034da339d80cea8eb11d74cfa21f314c9695a2caf3e57a
4
+ data.tar.gz: d77f9478512c78415a7299c234c4b5d16261cad6054c9df58e7a6c1756c94efb
5
+ SHA512:
6
+ metadata.gz: e0cb4f4b4d22b3e650a90984f46278e378310499fb34dc59a1ebeae084dd4b080be09445a364c5cb12ce272a63ad5e5cd4c9636864bf6b4c16ba2dff3dbc364f
7
+ data.tar.gz: eaf670a53aad6be0b883b62e66e30f755aab18502fb85c5ae3048906b52c181c7da0c09adfadc2c430159420eda89a6df607b1d0a801b5d27a9cce4c9a8aeb49
@@ -0,0 +1,20 @@
1
+ Copyright 2020 Intellum Inc.
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.
@@ -0,0 +1,52 @@
1
+ # Spinnaker::Sidekiq
2
+
3
+ API to implement a webhook stage for spinnaker to stop sidekiq workers gracefully.
4
+
5
+ ## Installation
6
+ Add this line to your application's Gemfile:
7
+
8
+ ```ruby
9
+ gem 'spinnaker-sidekiq'
10
+ ```
11
+
12
+ And then execute:
13
+ ```bash
14
+ $ bundle
15
+ ```
16
+
17
+ Or install it yourself as:
18
+ ```bash
19
+ $ gem install spinnaker-sidekiq
20
+ ```
21
+
22
+ ## Usage
23
+
24
+ Mount the engine in your rails application.
25
+
26
+ ``` ruby
27
+ mount Spinnaker::Sidekiq::Engine, at: "/spinnaker/sidekiq"
28
+ ```
29
+
30
+ API token can be specified by environment variable `SPINNAKER_SIDEKIQ_API_TOKEN` or doing:
31
+
32
+ ``` ruby
33
+ Spinnaker::Sidekiq.api_token = 'SECRET_VALUE'
34
+ ```
35
+
36
+ In spinnaker, create a webhook stage with the following configuration:
37
+
38
+ - Webhook URL: `https://example.com/spinnaker/sidekiq/quiet_all`
39
+ - Method: `POST`
40
+ - Payload `{}`
41
+ - Custom Headers:
42
+ `Authorization` value `Token SPINNAKER_API_TOKEN`
43
+ - Status JsonPath: `$.status`
44
+ - Progress location: `$.progress`
45
+ - SUCCESS status mapping: `quiet`
46
+
47
+
48
+ ## Contributing
49
+ Contribution directions go here.
50
+
51
+ ## License
52
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,32 @@
1
+ begin
2
+ require "bundler/setup"
3
+ rescue LoadError
4
+ puts "You must `gem install bundler` and `bundle install` to run rake tasks"
5
+ end
6
+
7
+ require "rdoc/task"
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = "rdoc"
11
+ rdoc.title = "Spinnaker::Sidekiq"
12
+ rdoc.options << "--line-numbers"
13
+ rdoc.rdoc_files.include("README.md")
14
+ rdoc.rdoc_files.include("lib/**/*.rb")
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
18
+ load "rails/tasks/engine.rake"
19
+
20
+ load "rails/tasks/statistics.rake"
21
+
22
+ require "bundler/gem_tasks"
23
+
24
+ require "rake/testtask"
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << "test"
28
+ t.pattern = "test/**/*_test.rb"
29
+ t.verbose = false
30
+ end
31
+
32
+ task default: :test
@@ -0,0 +1,47 @@
1
+ require_dependency "spinnaker/sidekiq/application_controller"
2
+ require "sidekiq/api"
3
+
4
+ module Spinnaker
5
+ module Sidekiq
6
+ class ApiController < ApplicationController
7
+ before_action :authenticate
8
+
9
+ # This will be used by a webhook stage to quiet all workers during deployment
10
+ def quiet_all
11
+ ps = ::Sidekiq::ProcessSet.new
12
+ ps.each(&:quiet!)
13
+ render plain: "", location: url_for(action: "status", started_at: Time.now.to_i)
14
+ end
15
+
16
+ # This will be used to poll the status of the sidekiq workers.
17
+ def status
18
+ ps = ::Sidekiq::ProcessSet.new
19
+
20
+ processes = ps.reject { |process|
21
+ params[:started_at] && process["started_at"] > DateTime.strptime(params[:started_at], "%s").to_i
22
+ }
23
+
24
+ busy_jobs = processes.sum { |process| process["busy"] }
25
+
26
+ status = busy_jobs == 0 ? "quiet" : "busy"
27
+
28
+ render json: {status: status, progress: "Pending jobs: #{busy_jobs}"}
29
+ end
30
+
31
+ private
32
+
33
+ def authenticate
34
+ authenticate_or_request_with_http_token do |token, _options|
35
+ token_digest = ::Digest::SHA256.hexdigest(token)
36
+ api_auth_token_digest = ::Digest::SHA256.hexdigest(api_authentication_token)
37
+
38
+ ActiveSupport::SecurityUtils.secure_compare(token_digest, api_auth_token_digest)
39
+ end
40
+ end
41
+
42
+ def api_authentication_token
43
+ Spinnaker::Sidekiq.api_token
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,6 @@
1
+ module Spinnaker
2
+ module Sidekiq
3
+ class ApplicationController < ActionController::Base
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,4 @@
1
+ Spinnaker::Sidekiq::Engine.routes.draw do
2
+ post "/quiet_all", to: "api#quiet_all"
3
+ get "/status", to: "api#status"
4
+ end
@@ -0,0 +1,19 @@
1
+ require "spinnaker/sidekiq/engine"
2
+
3
+ module Spinnaker
4
+ module Sidekiq
5
+ class MissingApiToken < StandardError
6
+ def initialize(msg = "Set SPINNAKER_SIDEKIQ_API_TOKEN environment variable or Spinnaker::Sidekiq.api_token")
7
+ super
8
+ end
9
+ end
10
+
11
+ class << self
12
+ attr_writer :api_token
13
+
14
+ def api_token
15
+ @api_token ||= ENV.fetch("SPINNAKER_SIDEKIQ_API_TOKEN") { raise MissingApiToken }
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,7 @@
1
+ module Spinnaker
2
+ module Sidekiq
3
+ class Engine < ::Rails::Engine
4
+ isolate_namespace Spinnaker::Sidekiq
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ module Spinnaker
2
+ module Sidekiq
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :spinnaker_sidekiq do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spinnaker-sidekiq
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jorge Dias
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-03-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 5.1.6
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 5.1.6.2
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: 5.1.6
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 5.1.6.2
33
+ - !ruby/object:Gem::Dependency
34
+ name: sidekiq
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '4.0'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '4.0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: sqlite3
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: standard
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: gem-release
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ description: API to implement a webhook stage for spinnaker to stop sidekiq workers
90
+ gracefully
91
+ email:
92
+ - jdias@intellum.com
93
+ executables: []
94
+ extensions: []
95
+ extra_rdoc_files: []
96
+ files:
97
+ - MIT-LICENSE
98
+ - README.md
99
+ - Rakefile
100
+ - app/controllers/spinnaker/sidekiq/api_controller.rb
101
+ - app/controllers/spinnaker/sidekiq/application_controller.rb
102
+ - config/routes.rb
103
+ - lib/spinnaker/sidekiq.rb
104
+ - lib/spinnaker/sidekiq/engine.rb
105
+ - lib/spinnaker/sidekiq/version.rb
106
+ - lib/tasks/spinnaker/sidekiq_tasks.rake
107
+ homepage: https://github.com/intellum/spinnaker-sidekiq
108
+ licenses:
109
+ - MIT
110
+ metadata: {}
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubygems_version: 3.0.3
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: Spinnaker Sidekiq integration
130
+ test_files: []