kuby-sidekiq 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/README.md +31 -0
- data/lib/kuby/sidekiq/plugin.rb +29 -75
- data/lib/kuby/sidekiq/sidekiq_process.rb +89 -0
- data/lib/kuby/sidekiq/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 96b955437e20df29e41ac12d18bcb7ae804af4858a35e58c1a29b54b76b16ee7
|
4
|
+
data.tar.gz: 183546d8e03bba59e1baa60e253a6abf682dfbbb1d450e5c550109016e7f1c5f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 64178547f2fa845ab5879cbe39d6d98d62e2fb56d8433fbc7748e69e93eff3502cd1c503ca563a270a233ee6b5d7cfe4145962817597eb1f52111daffe26a17f
|
7
|
+
data.tar.gz: 85516c3f5ba4c5f87ddf0e46dd13fe159eccf2d4ab86685840d7ff3e7ba3df3574df477ff498b6eea8ad0fd6a0b2bcbd1f2f22accdb568ac4f55de19a93c176a
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -66,6 +66,37 @@ bundle exec kuby -e production push
|
|
66
66
|
bundle exec kuby -e production deploy
|
67
67
|
```
|
68
68
|
|
69
|
+
## Advanced Configuration
|
70
|
+
|
71
|
+
If you have a more complex setup for Sidekiq you can specify the processes you need to create. The options method allow you to
|
72
|
+
provide command line arguments to Sidekiq in order to either specify a non-default `sidekiq.yml` file or queues for a process to
|
73
|
+
run. The process name is required.
|
74
|
+
|
75
|
+
```ruby
|
76
|
+
require 'kuby/sidekiq'
|
77
|
+
|
78
|
+
Kuby.define(:production) do
|
79
|
+
kubernetes do
|
80
|
+
|
81
|
+
add_plugin(:sidekiq) do
|
82
|
+
replicas 2 # sets the default number of replicas for each process
|
83
|
+
|
84
|
+
|
85
|
+
process('default') # sidekiq uses sidekiq.yml by default and has 2 replicas
|
86
|
+
|
87
|
+
process('slow_process') do
|
88
|
+
options ['-C', 'config/slow_sidekiq.yml']
|
89
|
+
replicas 4 # override default number of replicas
|
90
|
+
end
|
91
|
+
|
92
|
+
process('queue_processor') do
|
93
|
+
options ['-q', 'critical', '-q', 'less_critical']
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
```
|
99
|
+
|
69
100
|
## License
|
70
101
|
|
71
102
|
Licensed under the MIT license. See LICENSE for details.
|
data/lib/kuby/sidekiq/plugin.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'securerandom'
|
2
2
|
require 'kuby/redis'
|
3
|
+
require_relative 'sidekiq_process'
|
3
4
|
|
4
5
|
module Kuby
|
5
6
|
module Sidekiq
|
@@ -10,6 +11,10 @@ module Kuby
|
|
10
11
|
|
11
12
|
value_field :replicas, default: 1
|
12
13
|
|
14
|
+
def processes
|
15
|
+
@processes ||= []
|
16
|
+
end
|
17
|
+
|
13
18
|
def connection_params
|
14
19
|
redis_instance.connection_params
|
15
20
|
end
|
@@ -19,6 +24,10 @@ module Kuby
|
|
19
24
|
end
|
20
25
|
|
21
26
|
def after_configuration
|
27
|
+
if processes.empty?
|
28
|
+
processes << SidekiqProcess.new(plugin: self, default_replicas: replicas)
|
29
|
+
end
|
30
|
+
|
22
31
|
environment.kubernetes.add_plugin(:redis) do
|
23
32
|
instance :sidekiq do
|
24
33
|
custom_config (custom_config || []).concat(['maxmemory-policy noeviction'])
|
@@ -27,24 +36,28 @@ module Kuby
|
|
27
36
|
|
28
37
|
return unless rails_app
|
29
38
|
|
30
|
-
|
31
|
-
|
32
|
-
|
39
|
+
processes.each do |process|
|
40
|
+
process.deployment.spec.template.spec.container(:worker).merge!(
|
41
|
+
rails_app.deployment.spec.template.spec.container(:web), fields: [:env_from]
|
42
|
+
)
|
33
43
|
|
34
|
-
|
35
|
-
|
44
|
+
if rails_app.manage_database? && database = Kuby::Plugins::RailsApp::Database.get(rails_app)
|
45
|
+
database.plugin.configure_pod_spec(process.deployment.spec.template.spec)
|
46
|
+
end
|
36
47
|
end
|
37
48
|
end
|
38
49
|
|
39
50
|
def before_deploy(manifest)
|
40
51
|
image_with_tag = "#{docker.image.image_url}:#{kubernetes.tag || Kuby::Docker::LATEST_TAG}"
|
41
52
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
53
|
+
processes.each do |process|
|
54
|
+
process.deployment do
|
55
|
+
spec do
|
56
|
+
template do
|
57
|
+
spec do
|
58
|
+
container(:worker) do
|
59
|
+
image image_with_tag
|
60
|
+
end
|
48
61
|
end
|
49
62
|
end
|
50
63
|
end
|
@@ -53,10 +66,7 @@ module Kuby
|
|
53
66
|
end
|
54
67
|
|
55
68
|
def resources
|
56
|
-
@resources ||= [
|
57
|
-
service_account,
|
58
|
-
deployment
|
59
|
-
]
|
69
|
+
@resources ||= [service_account, *processes.map(&:deployment)]
|
60
70
|
end
|
61
71
|
|
62
72
|
def service_account(&block)
|
@@ -78,67 +88,11 @@ module Kuby
|
|
78
88
|
@service_account
|
79
89
|
end
|
80
90
|
|
81
|
-
def
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
metadata do
|
86
|
-
name "#{context.selector_app}-sidekiq-#{ROLE}"
|
87
|
-
namespace context.namespace.metadata.name
|
88
|
-
|
89
|
-
labels do
|
90
|
-
add :app, context.selector_app
|
91
|
-
add :role, ROLE
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
spec do
|
96
|
-
replicas context.replicas
|
97
|
-
|
98
|
-
selector do
|
99
|
-
match_labels do
|
100
|
-
add :app, context.selector_app
|
101
|
-
add :role, ROLE
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
strategy do
|
106
|
-
type 'RollingUpdate'
|
107
|
-
|
108
|
-
rolling_update do
|
109
|
-
max_surge '25%'
|
110
|
-
max_unavailable 0
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
template do
|
115
|
-
metadata do
|
116
|
-
labels do
|
117
|
-
add :app, context.selector_app
|
118
|
-
add :role, ROLE
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
spec do
|
123
|
-
container(:worker) do
|
124
|
-
name "#{context.selector_app}-sidekiq-#{ROLE}"
|
125
|
-
image_pull_policy 'IfNotPresent'
|
126
|
-
command %w(bundle exec sidekiq)
|
127
|
-
end
|
128
|
-
|
129
|
-
image_pull_secret do
|
130
|
-
name context.kubernetes.registry_secret.metadata.name
|
131
|
-
end
|
132
|
-
|
133
|
-
restart_policy 'Always'
|
134
|
-
service_account_name context.service_account.metadata.name
|
135
|
-
end
|
136
|
-
end
|
137
|
-
end
|
91
|
+
def process(name, &block)
|
92
|
+
SidekiqProcess.new(name: name, plugin: self, default_replicas: replicas).tap do |process|
|
93
|
+
process.instance_eval(&block) if block
|
94
|
+
processes << process
|
138
95
|
end
|
139
|
-
|
140
|
-
@deployment.instance_eval(&block) if block
|
141
|
-
@deployment
|
142
96
|
end
|
143
97
|
|
144
98
|
def redis_instance
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'securerandom'
|
2
|
+
|
3
|
+
module Kuby
|
4
|
+
module Sidekiq
|
5
|
+
# This class creates a deployment for a Sidekiq Process. A process is a single instance
|
6
|
+
# of Sidekiq. Each instance can be provided command line options to specify concurrency,
|
7
|
+
# config files or queues.
|
8
|
+
# https://github.com/sidekiq/sidekiq/wiki/Best-Practices#4-use-precise-terminology
|
9
|
+
class SidekiqProcess
|
10
|
+
extend ::KubeDSL::ValueFields
|
11
|
+
|
12
|
+
ROLE='worker'
|
13
|
+
|
14
|
+
attr_reader :plugin, :name, :default_replicas
|
15
|
+
|
16
|
+
value_field :replicas, default: nil
|
17
|
+
value_field :options, default: []
|
18
|
+
|
19
|
+
def initialize(name: 'default', plugin:, default_replicas:)
|
20
|
+
@name = name
|
21
|
+
@plugin = plugin
|
22
|
+
@default_replicas = default_replicas
|
23
|
+
end
|
24
|
+
|
25
|
+
def deployment(&block)
|
26
|
+
context = self
|
27
|
+
|
28
|
+
@deployment ||= KubeDSL.deployment do
|
29
|
+
metadata do
|
30
|
+
name "#{context.plugin.selector_app}-sidekiq-#{ROLE}-#{context.name}"
|
31
|
+
namespace context.plugin.namespace.metadata.name
|
32
|
+
|
33
|
+
labels do
|
34
|
+
add :app, context.plugin.selector_app
|
35
|
+
add :role, ROLE
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
spec do
|
40
|
+
replicas (context.replicas || context.default_replicas)
|
41
|
+
|
42
|
+
selector do
|
43
|
+
match_labels do
|
44
|
+
add :app, context.plugin.selector_app
|
45
|
+
add :role, ROLE
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
strategy do
|
50
|
+
type 'RollingUpdate'
|
51
|
+
|
52
|
+
rolling_update do
|
53
|
+
max_surge '25%'
|
54
|
+
max_unavailable 0
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
template do
|
59
|
+
metadata do
|
60
|
+
labels do
|
61
|
+
add :app, context.plugin.selector_app
|
62
|
+
add :role, ROLE
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
spec do
|
67
|
+
container(:worker) do
|
68
|
+
name "#{context.plugin.selector_app}-sidekiq-#{ROLE}-#{context.name}"
|
69
|
+
image_pull_policy 'IfNotPresent'
|
70
|
+
command ['bundle', 'exec', 'sidekiq', *context.options]
|
71
|
+
end
|
72
|
+
|
73
|
+
image_pull_secret do
|
74
|
+
name context.plugin.kubernetes.registry_secret.metadata.name
|
75
|
+
end
|
76
|
+
|
77
|
+
restart_policy 'Always'
|
78
|
+
service_account_name context.plugin.service_account.metadata.name
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
@deployment.instance_eval(&block) if block
|
85
|
+
@deployment
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
data/lib/kuby/sidekiq/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kuby-sidekiq
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cameron Dutro
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-03-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: kuby-core
|
@@ -73,6 +73,7 @@ files:
|
|
73
73
|
- kuby-sidekiq.gemspec
|
74
74
|
- lib/kuby/sidekiq.rb
|
75
75
|
- lib/kuby/sidekiq/plugin.rb
|
76
|
+
- lib/kuby/sidekiq/sidekiq_process.rb
|
76
77
|
- lib/kuby/sidekiq/version.rb
|
77
78
|
homepage: http://github.com/getkuby/kuby-sidekiq
|
78
79
|
licenses: []
|
@@ -92,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
93
|
- !ruby/object:Gem::Version
|
93
94
|
version: '0'
|
94
95
|
requirements: []
|
95
|
-
rubygems_version: 3.
|
96
|
+
rubygems_version: 3.4.5
|
96
97
|
signing_key:
|
97
98
|
specification_version: 4
|
98
99
|
summary: Sidekiq plugin for Kuby.
|