govuk_sidekiq 0.0.1
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 +7 -0
- data/LICENCE.txt +21 -0
- data/README.md +30 -0
- data/lib/govuk_sidekiq/api_headers.rb +33 -0
- data/lib/govuk_sidekiq/railtie.rb +11 -0
- data/lib/govuk_sidekiq/sidekiq_initializer.rb +36 -0
- data/lib/govuk_sidekiq/version.rb +3 -0
- data/lib/govuk_sidekiq.rb +1 -0
- metadata +177 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2fbf655d18d2914d3720c3b011abb49c5cf43895
|
4
|
+
data.tar.gz: ed5ccf95e8be8d80df17266e71a4a9a4deff459b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a51fe08e06acb4bb896bebe3d23f75f98440afc11c8a518bffeb411a792371687df95866bf97302d7183a8ac54216c9a8026f867310f4a6cfe1803f113bb63fa
|
7
|
+
data.tar.gz: 0278ff5f0f7058f99d44d8b498e74aaa12fe1ea49b0425d70f387fc9f00c1b25bc5665e54ce58a61ededa6c4c26a58841580a514e9c35c07691382cff2506e89
|
data/LICENCE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Crown Copyright (Government Digital Service)
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# GOVUK Sidekiq
|
2
|
+
|
3
|
+
Provides a unified set of configurations and behaviours when using Sidekiq
|
4
|
+
in GOV.UK applications.
|
5
|
+
|
6
|
+
## Technical documentation
|
7
|
+
|
8
|
+
When added to a Rails application, this gem uses a railtie to inject an
|
9
|
+
initializer configuring Sidekiq.
|
10
|
+
|
11
|
+
It includes our current optimal sidekiq configuration
|
12
|
+
including Airbrake/Errbit, statsd, JSON logging,
|
13
|
+
and passthrough of the `govuk_request_id`.
|
14
|
+
|
15
|
+
No other configuration is required other than the presence of the following
|
16
|
+
environment variables:
|
17
|
+
|
18
|
+
- **GOVUK_APP_NAME**, used for Redis and statsd namespacing.
|
19
|
+
- **REDIS_HOST**
|
20
|
+
- **REDIS_PORT**
|
21
|
+
|
22
|
+
This gem also assumes that the app has separately configured and required Airbrake/Errbit.
|
23
|
+
|
24
|
+
## Licence
|
25
|
+
|
26
|
+
[MIT License](LICENCE)
|
27
|
+
|
28
|
+
## Versioning policy
|
29
|
+
|
30
|
+
See https://github.com/alphagov/styleguides/blob/master/rubygems.md#versioning
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require "gds_api/govuk_headers"
|
2
|
+
|
3
|
+
module GovukSidekiq
|
4
|
+
module APIHeaders
|
5
|
+
# Client-side middleware runs before the pushing of the job to Redis and
|
6
|
+
# allows you to modify/stop the job before it gets pushed.
|
7
|
+
#
|
8
|
+
# https://github.com/mperham/sidekiq/wiki/Middleware#client-side-middleware
|
9
|
+
class ClientMiddleware
|
10
|
+
def call(worker_class, job, queue, redis_pool)
|
11
|
+
job["args"] << { request_id: GdsApi::GovukHeaders.headers[:govuk_request_id] }
|
12
|
+
yield
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# Server-side middleware runs 'around' job processing.
|
17
|
+
#
|
18
|
+
# https://github.com/mperham/sidekiq/wiki/Middleware#server-side-middleware
|
19
|
+
class ServerMiddleware
|
20
|
+
def call(worker, message, queue)
|
21
|
+
last_arg = message["args"].last
|
22
|
+
|
23
|
+
if last_arg.is_a?(Hash) && last_arg.keys == ["request_id"]
|
24
|
+
message["args"].pop
|
25
|
+
request_id = last_arg["request_id"]
|
26
|
+
GdsApi::GovukHeaders.set_header(:govuk_request_id, request_id)
|
27
|
+
end
|
28
|
+
|
29
|
+
yield
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module GovukSidekiq
|
2
|
+
class Railtie < Rails::Railtie
|
3
|
+
initializer "govuk_sidekiq.initialize_sidekiq" do |app|
|
4
|
+
SidekiqInitializer.setup_sidekiq(
|
5
|
+
ENV["GOVUK_APP_NAME"] || app.root.basename.to_s,
|
6
|
+
ENV["REDIS_HOST"] || "127.0.0.1",
|
7
|
+
ENV["REDIS_PORT"] || 6379
|
8
|
+
)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require "sidekiq"
|
2
|
+
require "sidekiq/logging/json"
|
3
|
+
require "airbrake"
|
4
|
+
require "govuk_sidekiq/api_headers"
|
5
|
+
|
6
|
+
module GovukSidekiq
|
7
|
+
module SidekiqInitializer
|
8
|
+
def self.setup_sidekiq(govuk_app_name, redis_host, redis_port)
|
9
|
+
redis_config = {
|
10
|
+
host: redis_host,
|
11
|
+
port: redis_port,
|
12
|
+
namespace: govuk_app_name,
|
13
|
+
}
|
14
|
+
|
15
|
+
Sidekiq.configure_server do |config|
|
16
|
+
config.redis = redis_config
|
17
|
+
config.error_handlers << Proc.new { |ex, context_hash| Airbrake.notify(ex, context_hash) }
|
18
|
+
|
19
|
+
config.server_middleware do |chain|
|
20
|
+
chain.add Sidekiq::Statsd::ServerMiddleware, env: "govuk.app.#{govuk_app_name}", prefix: "workers"
|
21
|
+
chain.add GovukSidekiq::APIHeaders::ServerMiddleware
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
Sidekiq.configure_client do |config|
|
26
|
+
config.redis = redis_config
|
27
|
+
|
28
|
+
config.client_middleware do |chain|
|
29
|
+
chain.add GovukSidekiq::APIHeaders::ClientMiddleware
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
Sidekiq.logger.formatter = Sidekiq::Logging::Json::Logger.new
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require "govuk_sidekiq/railtie" if defined?(Rails)
|
metadata
ADDED
@@ -0,0 +1,177 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: govuk_sidekiq
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Elliot Crosby-McCullough
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-06-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: sidekiq
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sidekiq-statsd
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.1'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.1'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: sidekiq-logging-json
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: gds-api-adapters
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 19.1.0
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 19.1.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: airbrake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 3.1.0
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 3.1.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.4'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.4'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rake
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '11.1'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '11.1'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: bundler
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '1.10'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '1.10'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: gem_publisher
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - '='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 1.5.0
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - '='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 1.5.0
|
139
|
+
description:
|
140
|
+
email:
|
141
|
+
- elliot.cm@gmail.com
|
142
|
+
executables: []
|
143
|
+
extensions: []
|
144
|
+
extra_rdoc_files: []
|
145
|
+
files:
|
146
|
+
- LICENCE.txt
|
147
|
+
- README.md
|
148
|
+
- lib/govuk_sidekiq.rb
|
149
|
+
- lib/govuk_sidekiq/api_headers.rb
|
150
|
+
- lib/govuk_sidekiq/railtie.rb
|
151
|
+
- lib/govuk_sidekiq/sidekiq_initializer.rb
|
152
|
+
- lib/govuk_sidekiq/version.rb
|
153
|
+
homepage: http://github.com/alphagov/govuk_sidekiq
|
154
|
+
licenses:
|
155
|
+
- MIT
|
156
|
+
metadata: {}
|
157
|
+
post_install_message:
|
158
|
+
rdoc_options: []
|
159
|
+
require_paths:
|
160
|
+
- lib
|
161
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
162
|
+
requirements:
|
163
|
+
- - ">="
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: '0'
|
166
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
167
|
+
requirements:
|
168
|
+
- - ">="
|
169
|
+
- !ruby/object:Gem::Version
|
170
|
+
version: '0'
|
171
|
+
requirements: []
|
172
|
+
rubyforge_project:
|
173
|
+
rubygems_version: 2.5.1
|
174
|
+
signing_key:
|
175
|
+
specification_version: 4
|
176
|
+
summary: Provides standard setup and behaviour for Sidekiq in GOV.UK applications.
|
177
|
+
test_files: []
|