sidekiq-redeploy 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +2 -0
- data/.rubocop.yml +46 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +96 -0
- data/Rakefile +16 -0
- data/bin/sidekiq-loader +57 -0
- data/lib/sidekiq/redeploy/loader.rb +162 -0
- data/lib/sidekiq/redeploy/version.rb +7 -0
- data/lib/sidekiq/redeploy.rb +10 -0
- data/lib/sidekiq-redeploy.rb +3 -0
- data/lib/sidekiq_redeploy.rb +10 -0
- data/sidekiq-redeploy.gemspec +47 -0
- data/sig/sidekiq/redeploy.rbs +6 -0
- metadata +212 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d3fbc7cfc251f0ac96afc18cd2273187334c4df1031ffc4cb4d6c66ed8387bd8
|
4
|
+
data.tar.gz: 38d20ad778db5776efad55be6bab8a45672bc869d7c3dd29898f8869ce31bc4b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dca0a368ff1dfa70e86e3ced5c94247fbe768b70fd38808a635d637747b327f4684d761a1de49ee9b8581b19833b1464b57efd8df318b41f59a5ebbfd8b48bb4
|
7
|
+
data.tar.gz: 5adfd730bc05cba24fc31d8672cdf72454fc6d5bbc82d40b309335a9837d245103e2871bc332ddacaab85635f7c572d40fff4c4f22cb3d26c127a94540cca98b
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 3.1
|
3
|
+
DisplayCopNames: true
|
4
|
+
SuggestExtensions: false
|
5
|
+
NewCops: enable
|
6
|
+
Exclude:
|
7
|
+
- 'lib/sidekiq-redeploy.rb'
|
8
|
+
|
9
|
+
require:
|
10
|
+
- rubocop-rake
|
11
|
+
- rubocop-performance
|
12
|
+
- rubocop-rspec
|
13
|
+
- rubocop-thread_safety
|
14
|
+
|
15
|
+
Metrics/BlockLength:
|
16
|
+
AllowedMethods: ['describe', 'context']
|
17
|
+
|
18
|
+
Metrics/MethodLength:
|
19
|
+
Max: 30
|
20
|
+
|
21
|
+
Metrics/ClassLength:
|
22
|
+
Max: 120
|
23
|
+
|
24
|
+
RSpec/NestedGroups:
|
25
|
+
Max: 4
|
26
|
+
|
27
|
+
RSpec/MultipleMemoizedHelpers:
|
28
|
+
Max: 12
|
29
|
+
|
30
|
+
RSpec/ExampleLength:
|
31
|
+
Max: 6
|
32
|
+
|
33
|
+
RSpec/ExpectInHook:
|
34
|
+
Enabled: false
|
35
|
+
|
36
|
+
RSpec/StubbedMock:
|
37
|
+
Enabled: false
|
38
|
+
|
39
|
+
RSpec/MessageSpies:
|
40
|
+
Enabled: false
|
41
|
+
|
42
|
+
RSpec/MultipleExpectations:
|
43
|
+
Max: 2
|
44
|
+
|
45
|
+
RSpec/SubjectStub:
|
46
|
+
Enabled: false
|
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
8
|
+
|
9
|
+
## Our Standards
|
10
|
+
|
11
|
+
Examples of behavior that contributes to a positive environment for our community include:
|
12
|
+
|
13
|
+
* Demonstrating empathy and kindness toward other people
|
14
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
15
|
+
* Giving and gracefully accepting constructive feedback
|
16
|
+
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
17
|
+
* Focusing on what is best not just for us as individuals, but for the overall community
|
18
|
+
|
19
|
+
Examples of unacceptable behavior include:
|
20
|
+
|
21
|
+
* The use of sexualized language or imagery, and sexual attention or
|
22
|
+
advances of any kind
|
23
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
24
|
+
* Public or private harassment
|
25
|
+
* Publishing others' private information, such as a physical or email
|
26
|
+
address, without their explicit permission
|
27
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
28
|
+
professional setting
|
29
|
+
|
30
|
+
## Enforcement Responsibilities
|
31
|
+
|
32
|
+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
33
|
+
|
34
|
+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
35
|
+
|
36
|
+
## Scope
|
37
|
+
|
38
|
+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
39
|
+
|
40
|
+
## Enforcement
|
41
|
+
|
42
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at tbeauvais1@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
|
43
|
+
|
44
|
+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
45
|
+
|
46
|
+
## Enforcement Guidelines
|
47
|
+
|
48
|
+
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
49
|
+
|
50
|
+
### 1. Correction
|
51
|
+
|
52
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
53
|
+
|
54
|
+
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
55
|
+
|
56
|
+
### 2. Warning
|
57
|
+
|
58
|
+
**Community Impact**: A violation through a single incident or series of actions.
|
59
|
+
|
60
|
+
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
|
61
|
+
|
62
|
+
### 3. Temporary Ban
|
63
|
+
|
64
|
+
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
65
|
+
|
66
|
+
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
67
|
+
|
68
|
+
### 4. Permanent Ban
|
69
|
+
|
70
|
+
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
71
|
+
|
72
|
+
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
73
|
+
|
74
|
+
## Attribution
|
75
|
+
|
76
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
|
77
|
+
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
78
|
+
|
79
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
|
80
|
+
|
81
|
+
[homepage]: https://www.contributor-covenant.org
|
82
|
+
|
83
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
84
|
+
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2023 tbeauvais
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
# Sidekiq Redeploy
|
2
|
+
|
3
|
+
The sidekiq-redeploy gem is a sidekiq launcher that allows you to redeploy a new version of your Ruby application in a container without a full container deploy.
|
4
|
+
|
5
|
+
Key Points:
|
6
|
+
* Encourages the separation of the build process from deployment
|
7
|
+
* Deploys in seconds
|
8
|
+
* Pluggable handlers to detect redeploy (File, S3, Artifactory, etc..)
|
9
|
+
|
10
|
+
![image](https://user-images.githubusercontent.com/121275/235370300-b1430140-e8de-4641-840e-016d97050df5.png)
|
11
|
+
|
12
|
+
|
13
|
+
Example application can be found [here](https://github.com/tbeauvais/puma-redeploy-test-app)
|
14
|
+
See related [puma-redeploy](https://github.com/tbeauvais/puma-redeploy) gem
|
15
|
+
|
16
|
+
## Installation
|
17
|
+
|
18
|
+
Add this line to your application's Gemfile:
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
gem 'sidekiq-redeploy'
|
22
|
+
```
|
23
|
+
|
24
|
+
And then execute:
|
25
|
+
|
26
|
+
$ bundle install
|
27
|
+
|
28
|
+
Or install it yourself as:
|
29
|
+
|
30
|
+
$ gem install sidekiq-redeploy
|
31
|
+
|
32
|
+
## Usage
|
33
|
+
|
34
|
+
The `sidekiq-loader` is a cli used to start Sidekiq in a child process and monitor for application updates.
|
35
|
+
|
36
|
+
```shell
|
37
|
+
Usage: sidekiq-loader [options]
|
38
|
+
-a, --app-dir=DIR [Required] Location of application directory.
|
39
|
+
-w, --watch=WATCH [Required] Location of watch file (file or s3 location).
|
40
|
+
-y, --watch-delay INTEGER [Optional] Specify the number of seconds between checking watch file. Defaults to 30.
|
41
|
+
-d, --[no-]deploy [FLAG] [Optional] Deploy archive on app startup. Defaults to true.
|
42
|
+
-s, --sidekiq-app [PATH|DIR] [Optional] Location of application to pass to sidekiq.
|
43
|
+
```
|
44
|
+
|
45
|
+
For example this will start the launcher using a S3 watch file.
|
46
|
+
```shell
|
47
|
+
bundle exec sidekiq-loader -a /app -w s3://puma-test-app-archives/watch.me
|
48
|
+
```
|
49
|
+
|
50
|
+
In the example above the `watch.me` contents would look like the following. In this case the `test_app_0.0.3.zip` must exist in the `puma-test-app-archives` S3 bucket.
|
51
|
+
```shell
|
52
|
+
s3://puma-test-app-archives/test_app_0.0.3.zip
|
53
|
+
```
|
54
|
+
|
55
|
+
You can optionally use the `-s` option to specify the application file for sidekiq to run. This is useful when running a Sinatra app.
|
56
|
+
```shell
|
57
|
+
bundle exec sidekiq-loader -a /app -w s3://puma-test-app-archives/watch.me -s ./app.rb
|
58
|
+
```
|
59
|
+
### Signals
|
60
|
+
Signals can be used to send commands to the sidekiq-loader. The following signals are supported. Also see https://github.com/sidekiq/sidekiq/wiki/Signals.
|
61
|
+
|
62
|
+
For example you can shell into your container and issue a signal using the `kill` command.
|
63
|
+
```shell
|
64
|
+
kill -USR2 pid
|
65
|
+
```
|
66
|
+
|
67
|
+
* USR2 - This signal will trigger a restart of the Sidekiq process. The Sidekiq process will be first issues a `TSTP` quiet signal, and then a `TERM` signal. This is useful in a non-production environment if you want to shell into the container, modify code, and the restart Sidekiq.
|
68
|
+
* TERM,INT - This signal will first issue a `TERM` signal to Sidekiq (giving it time to shutdown), and then shutdown sidekiq-loader.
|
69
|
+
* TTIN - This signal will be sent to Sidekiq which will print backtraces for all threads to STDOUT.
|
70
|
+
|
71
|
+
## Development
|
72
|
+
|
73
|
+
After checking out the repo, run `bundle` to install dependencies. Then, run `rake spec` to run the tests and `rake rubocop` to check for rubocop offences.
|
74
|
+
|
75
|
+
To install this gem onto your local machine, run the following. **Note** - You must add any new files to git first.
|
76
|
+
|
77
|
+
```text
|
78
|
+
bundle exec rake install
|
79
|
+
sidekiq-redeploy 0.1.0 built to pkg/sidekiq-redeploy-0.1.0.gem.
|
80
|
+
sidekiq-redeploy (0.1.0) installed.
|
81
|
+
```
|
82
|
+
|
83
|
+
To release a new version, update the version number in `version.rb`, and then run the Release GitHub action.
|
84
|
+
|
85
|
+
|
86
|
+
## Contributing
|
87
|
+
|
88
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/tbeauvais/sidekiq-redeploy. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/tbeauvais/sidekiq-redeploy/blob/main/CODE_OF_CONDUCT.md).
|
89
|
+
|
90
|
+
## License
|
91
|
+
|
92
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
93
|
+
|
94
|
+
## Code of Conduct
|
95
|
+
|
96
|
+
Everyone interacting in the Sidekiq::Redeploy project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/tbeauvais/sidekiq-redeploy/blob/main/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
|
6
|
+
begin
|
7
|
+
# Add rubocop task
|
8
|
+
require 'rubocop/rake_task'
|
9
|
+
RuboCop::RakeTask.new
|
10
|
+
rescue LoadError
|
11
|
+
# Ignore
|
12
|
+
end
|
13
|
+
|
14
|
+
RSpec::Core::RakeTask.new(:spec)
|
15
|
+
|
16
|
+
task default: :spec
|
data/bin/sidekiq-loader
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'sidekiq-redeploy'
|
6
|
+
require 'puma-redeploy'
|
7
|
+
|
8
|
+
def run_sidekiq(ops, logger)
|
9
|
+
deployer = Puma::Redeploy::DeployerFactory.create(target: ops[:app_dir], watch_file: ops[:watch], logger:)
|
10
|
+
|
11
|
+
# Load app archive on launch
|
12
|
+
deployer.deploy(source: deployer.archive_file) if ops[:deploy]
|
13
|
+
config = { watch_delay: ops[:watch_delay] }
|
14
|
+
|
15
|
+
Sidekiq::Redeploy::Loader.new(deployer:, logger:, sidekiq_app: ops[:sidekiq_app], config:).run
|
16
|
+
end
|
17
|
+
|
18
|
+
def option_parser(opts)
|
19
|
+
OptionParser.new do |o|
|
20
|
+
o.on '-a', '--app-dir=DIR', '[Required] Location of application directory.' do |arg|
|
21
|
+
opts[:app_dir] = arg
|
22
|
+
end
|
23
|
+
|
24
|
+
o.on '-w', '--watch=WATCH', '[Required] Location of watch file (file or s3 location).' do |arg|
|
25
|
+
opts[:watch] = arg
|
26
|
+
end
|
27
|
+
|
28
|
+
o.on '-y', '--watch-delay INTEGER', Integer,
|
29
|
+
'[Optional] Specify the number of seconds between checking watch file. Defaults to 30.' do |arg|
|
30
|
+
opts[:watch_delay] = arg
|
31
|
+
end
|
32
|
+
|
33
|
+
o.on '-d', '--[no-]deploy [FLAG]', TrueClass,
|
34
|
+
'[Optional] Deploy archive on app startup. Defaults to true.' do |arg|
|
35
|
+
opts[:deploy] = arg
|
36
|
+
end
|
37
|
+
|
38
|
+
o.on '-s', '--sidekiq-app [PATH|DIR]', '[Optional] Location of application to pass to sidekiq.' do |arg|
|
39
|
+
opts[:sidekiq_app] = arg
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def logger
|
45
|
+
Logger.new($stdout)
|
46
|
+
end
|
47
|
+
|
48
|
+
ops = { deploy: true, watch_delay: 30 }
|
49
|
+
parser = option_parser(ops)
|
50
|
+
parser.parse!(ARGV)
|
51
|
+
|
52
|
+
unless ops[:app_dir] && ops[:watch]
|
53
|
+
puts parser.help
|
54
|
+
exit 1
|
55
|
+
end
|
56
|
+
|
57
|
+
run_sidekiq(ops, logger)
|
@@ -0,0 +1,162 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'sidekiq'
|
4
|
+
require 'sidekiq/cli'
|
5
|
+
require 'logger'
|
6
|
+
|
7
|
+
module Sidekiq
|
8
|
+
module Redeploy
|
9
|
+
# Loads sidekiq process and monitors for redeploy
|
10
|
+
class Loader
|
11
|
+
USR2 = 'USR2' # Signal to sidekiq redeploy loader to restart a new Sidekiq process
|
12
|
+
TTIN = 'TTIN' # Signal to sidekiq to print backtraces for all threads
|
13
|
+
TSTP = 'TSTP' # Signal to sidekiq that it will be shutting down soon and it should stop taking jobs.
|
14
|
+
TERM = 'TERM' # Signal to shutdown the loader after shutdown of sidekiq process
|
15
|
+
INT = 'INT' # Signal to shutdown the loader after shutdown of sidekiq process
|
16
|
+
|
17
|
+
SIGNALS = [INT, TERM, USR2, TTIN].freeze
|
18
|
+
|
19
|
+
def initialize(deployer:, sidekiq_app: nil, logger: Logger.new($stdout), config: {})
|
20
|
+
@reload_sidekiq = false
|
21
|
+
@exit_loader = false
|
22
|
+
@loader_pid = Process.pid
|
23
|
+
@logger = logger
|
24
|
+
@signal_delay = config[:signal_delay] || 1
|
25
|
+
@watch_delay = config[:watch_delay] || 30
|
26
|
+
@watch_time = Time.now
|
27
|
+
@loop_delay = config[:loop_delay] || 0.5
|
28
|
+
@deployer = deployer
|
29
|
+
@sidekiq_app = sidekiq_app
|
30
|
+
end
|
31
|
+
|
32
|
+
def run
|
33
|
+
log "Starting sidekiq reloader... pid=#{@loader_pid}"
|
34
|
+
|
35
|
+
trap_signals
|
36
|
+
|
37
|
+
fork_sidekiq
|
38
|
+
|
39
|
+
process_loop
|
40
|
+
|
41
|
+
log 'Waiting for Sidekiq process to end'
|
42
|
+
Process.waitall
|
43
|
+
|
44
|
+
log 'Shutting down sidekiq reloader'
|
45
|
+
rescue StandardError => e
|
46
|
+
log "Error in sidekiq loader: #{e.message}"
|
47
|
+
log e.backtrace.join("\n")
|
48
|
+
stop_sidekiq(@sidekiq_pid)
|
49
|
+
Process.waitall
|
50
|
+
exit 1
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
attr_reader :exit_loader, :reload_sidekiq, :signal_delay, :loop_delay, :deployer, :logger
|
56
|
+
|
57
|
+
def process_loop
|
58
|
+
loop do
|
59
|
+
sleep(loop_delay)
|
60
|
+
if needs_redeploy?
|
61
|
+
reload_app { deployer.deploy(source: deployer.archive_file) }
|
62
|
+
elsif reload_sidekiq
|
63
|
+
reload_app
|
64
|
+
elsif process_died?(@sidekiq_pid)
|
65
|
+
fork_sidekiq
|
66
|
+
end
|
67
|
+
next unless exit_loader
|
68
|
+
|
69
|
+
stop_sidekiq(@sidekiq_pid)
|
70
|
+
break
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def needs_redeploy?
|
75
|
+
return unless (Time.now - @watch_time) > @watch_delay
|
76
|
+
|
77
|
+
@watch_time = Time.now
|
78
|
+
log 'Checking watch file for redeploy'
|
79
|
+
deployer.needs_redeploy?
|
80
|
+
end
|
81
|
+
|
82
|
+
def reload_app
|
83
|
+
quiet_sidekiq(@sidekiq_pid)
|
84
|
+
|
85
|
+
yield if block_given?
|
86
|
+
|
87
|
+
stop_sidekiq(@sidekiq_pid)
|
88
|
+
|
89
|
+
# wait for sidekiq to stop
|
90
|
+
Process.waitall
|
91
|
+
|
92
|
+
fork_sidekiq
|
93
|
+
@reload_sidekiq = false
|
94
|
+
end
|
95
|
+
|
96
|
+
def fork_sidekiq
|
97
|
+
@sidekiq_pid = Process.fork do
|
98
|
+
cli = Sidekiq::CLI.instance
|
99
|
+
args = @sidekiq_app ? ['-r', @sidekiq_app] : []
|
100
|
+
cli.parse(args)
|
101
|
+
cli.run
|
102
|
+
rescue StandardError => e
|
103
|
+
message "Error loading sidekiq process: #{e.message}"
|
104
|
+
log message
|
105
|
+
log e.backtrace.join("\n")
|
106
|
+
raise message
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def trap_signals
|
111
|
+
SIGNALS.each do |signal|
|
112
|
+
Signal.trap(signal) do
|
113
|
+
handle_signal(signal)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
# There are limitations as to what to can do in a signal trap handler
|
119
|
+
# See https://github.com/ruby/ruby/blob/ruby_3_2/doc/signals.rdoc
|
120
|
+
def handle_signal(signal)
|
121
|
+
debug_handler(signal)
|
122
|
+
# Our handle_signal gets called for child processes (i.e. sidekiq process) so we don't want to re-handle these.
|
123
|
+
return if @loader_pid != Process.pid
|
124
|
+
|
125
|
+
case signal
|
126
|
+
when USR2
|
127
|
+
@reload_sidekiq = true
|
128
|
+
when TTIN
|
129
|
+
Process.kill(signal, @sidekiq_pid)
|
130
|
+
when TERM, INT
|
131
|
+
@exit_loader = true
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
def debug_handler(signal)
|
136
|
+
log_data = { signal:, current_pid: Process.pid, loader_pid: @loader_pid, sidekiq_pid: @sidekiq_pid,
|
137
|
+
reload_sidekiq: @reload_sidekiq, exit_loader: @exit_loader }
|
138
|
+
puts "handle_signal called with #{log_data}"
|
139
|
+
end
|
140
|
+
|
141
|
+
def stop_sidekiq(pid)
|
142
|
+
Process.kill(TERM, pid) if pid
|
143
|
+
end
|
144
|
+
|
145
|
+
def quiet_sidekiq(pid)
|
146
|
+
Process.kill(TSTP, pid) if pid
|
147
|
+
end
|
148
|
+
|
149
|
+
def process_died?(pid)
|
150
|
+
return false if @exit_loader
|
151
|
+
|
152
|
+
!Process.getpgid(pid)
|
153
|
+
rescue StandardError
|
154
|
+
true
|
155
|
+
end
|
156
|
+
|
157
|
+
def log(message)
|
158
|
+
logger&.info message
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/sidekiq/redeploy/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'sidekiq-redeploy'
|
7
|
+
spec.version = Sidekiq::Redeploy::VERSION
|
8
|
+
spec.authors = ['tbeauvais']
|
9
|
+
spec.email = ['tbeauvais1@gmail.com']
|
10
|
+
|
11
|
+
spec.summary = 'Sidekiq launcher to redeploy and reload app from artifact.'
|
12
|
+
spec.description = 'Sidekiq launcher to redeploy and reload app from a remote artifact. ' \
|
13
|
+
'This will detect app changes, once detected a new artifact ' \
|
14
|
+
'will be pulled and the Sidekiq app will be reloaded.'
|
15
|
+
spec.homepage = 'https://github.com/tbeauvais/sidekiq-redeploy'
|
16
|
+
spec.license = 'MIT'
|
17
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 3.1.0')
|
18
|
+
|
19
|
+
spec.executables = ['sidekiq-loader']
|
20
|
+
|
21
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
22
|
+
spec.metadata['source_code_uri'] = 'https://github.com/tbeauvais/sidekiq-redeploy'
|
23
|
+
spec.metadata['changelog_uri'] = 'https://github.com/tbeauvais/sidekiq-redeploy/CHANGELOG.md'
|
24
|
+
|
25
|
+
# Specify which files should be added to the gem when it is released.
|
26
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
27
|
+
spec.files = Dir.chdir(__dir__) do
|
28
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
29
|
+
(File.expand_path(f) == __FILE__) || f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor])
|
30
|
+
end
|
31
|
+
end
|
32
|
+
spec.bindir = 'bin'
|
33
|
+
spec.require_paths = ['lib']
|
34
|
+
|
35
|
+
spec.add_dependency 'puma-redeploy', '~> 0.2', '>= 0.2.1'
|
36
|
+
spec.add_dependency 'sidekiq', '~> 6.0'
|
37
|
+
|
38
|
+
spec.add_development_dependency 'rake', '~> 13.0.6'
|
39
|
+
spec.add_development_dependency 'rspec', '~> 3.12.0'
|
40
|
+
spec.add_development_dependency 'rubocop', '~> 1.43'
|
41
|
+
spec.add_development_dependency 'rubocop-performance', '~> 1.15'
|
42
|
+
spec.add_development_dependency 'rubocop-rake', '~> 0.6.0'
|
43
|
+
spec.add_development_dependency 'rubocop-rspec', '~> 2.17'
|
44
|
+
spec.add_development_dependency 'rubocop-thread_safety', '~> 0.4.4'
|
45
|
+
spec.add_development_dependency 'timecop', '~> 0.9.6'
|
46
|
+
spec.metadata['rubygems_mfa_required'] = 'true'
|
47
|
+
end
|
metadata
ADDED
@@ -0,0 +1,212 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sidekiq-redeploy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- tbeauvais
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-04-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: puma-redeploy
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.2'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.2.1
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0.2'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.2.1
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: sidekiq
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '6.0'
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '6.0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rake
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 13.0.6
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 13.0.6
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: rspec
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: 3.12.0
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 3.12.0
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: rubocop
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '1.43'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '1.43'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: rubocop-performance
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '1.15'
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - "~>"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '1.15'
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: rubocop-rake
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - "~>"
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 0.6.0
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - "~>"
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: 0.6.0
|
117
|
+
- !ruby/object:Gem::Dependency
|
118
|
+
name: rubocop-rspec
|
119
|
+
requirement: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - "~>"
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '2.17'
|
124
|
+
type: :development
|
125
|
+
prerelease: false
|
126
|
+
version_requirements: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - "~>"
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '2.17'
|
131
|
+
- !ruby/object:Gem::Dependency
|
132
|
+
name: rubocop-thread_safety
|
133
|
+
requirement: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - "~>"
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: 0.4.4
|
138
|
+
type: :development
|
139
|
+
prerelease: false
|
140
|
+
version_requirements: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - "~>"
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: 0.4.4
|
145
|
+
- !ruby/object:Gem::Dependency
|
146
|
+
name: timecop
|
147
|
+
requirement: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - "~>"
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: 0.9.6
|
152
|
+
type: :development
|
153
|
+
prerelease: false
|
154
|
+
version_requirements: !ruby/object:Gem::Requirement
|
155
|
+
requirements:
|
156
|
+
- - "~>"
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: 0.9.6
|
159
|
+
description: Sidekiq launcher to redeploy and reload app from a remote artifact. This
|
160
|
+
will detect app changes, once detected a new artifact will be pulled and the Sidekiq
|
161
|
+
app will be reloaded.
|
162
|
+
email:
|
163
|
+
- tbeauvais1@gmail.com
|
164
|
+
executables:
|
165
|
+
- sidekiq-loader
|
166
|
+
extensions: []
|
167
|
+
extra_rdoc_files: []
|
168
|
+
files:
|
169
|
+
- ".rspec"
|
170
|
+
- ".rubocop.yml"
|
171
|
+
- CHANGELOG.md
|
172
|
+
- CODE_OF_CONDUCT.md
|
173
|
+
- Gemfile
|
174
|
+
- LICENSE.txt
|
175
|
+
- README.md
|
176
|
+
- Rakefile
|
177
|
+
- bin/sidekiq-loader
|
178
|
+
- lib/sidekiq-redeploy.rb
|
179
|
+
- lib/sidekiq/redeploy.rb
|
180
|
+
- lib/sidekiq/redeploy/loader.rb
|
181
|
+
- lib/sidekiq/redeploy/version.rb
|
182
|
+
- lib/sidekiq_redeploy.rb
|
183
|
+
- sidekiq-redeploy.gemspec
|
184
|
+
- sig/sidekiq/redeploy.rbs
|
185
|
+
homepage: https://github.com/tbeauvais/sidekiq-redeploy
|
186
|
+
licenses:
|
187
|
+
- MIT
|
188
|
+
metadata:
|
189
|
+
homepage_uri: https://github.com/tbeauvais/sidekiq-redeploy
|
190
|
+
source_code_uri: https://github.com/tbeauvais/sidekiq-redeploy
|
191
|
+
changelog_uri: https://github.com/tbeauvais/sidekiq-redeploy/CHANGELOG.md
|
192
|
+
rubygems_mfa_required: 'true'
|
193
|
+
post_install_message:
|
194
|
+
rdoc_options: []
|
195
|
+
require_paths:
|
196
|
+
- lib
|
197
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
198
|
+
requirements:
|
199
|
+
- - ">="
|
200
|
+
- !ruby/object:Gem::Version
|
201
|
+
version: 3.1.0
|
202
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
203
|
+
requirements:
|
204
|
+
- - ">="
|
205
|
+
- !ruby/object:Gem::Version
|
206
|
+
version: '0'
|
207
|
+
requirements: []
|
208
|
+
rubygems_version: 3.3.5
|
209
|
+
signing_key:
|
210
|
+
specification_version: 4
|
211
|
+
summary: Sidekiq launcher to redeploy and reload app from artifact.
|
212
|
+
test_files: []
|