sidekiq-control 0.0.10
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/.editorconfig +15 -0
- data/.gitignore +16 -0
- data/.rspec +3 -0
- data/.rubocop.yml +58 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +21 -0
- data/README.md +51 -0
- data/Rakefile +26 -0
- data/bin/console +10 -0
- data/bin/setup +8 -0
- data/lib/sidekiq/control/configuration.rb +64 -0
- data/lib/sidekiq/control/version.rb +7 -0
- data/lib/sidekiq/control/web/application.rb +49 -0
- data/lib/sidekiq/control/web/helpers.rb +36 -0
- data/lib/sidekiq/control/web/params_parser.rb +39 -0
- data/lib/sidekiq/control/worker/instance.rb +62 -0
- data/lib/sidekiq/control/worker/param.rb +38 -0
- data/lib/sidekiq/control.rb +36 -0
- data/lib/sidekiq-control.rb +3 -0
- data/sidekiq-control.gemspec +40 -0
- data/web/locales/en.yml +16 -0
- data/web/views/error.erb +23 -0
- data/web/views/index.erb +32 -0
- data/web/views/show_job.erb +68 -0
- metadata +217 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d46ff3c3ad350d4aba51165584814385839f5695da359e07962f72ecb1df7486
|
4
|
+
data.tar.gz: df98cff0d954c1730dc239c42f8e46e6bf0590219a094271ca5bacbbe3162172
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e5397b21d4237eec071b9d2b962359e31bff9bc71c499843abd2e3d130e2dcc9ab5613b42325a94eab347c1026cc2abd7ef0482cf5ffa0cfd5921848caaf1356
|
7
|
+
data.tar.gz: 69e63cbea5c20d7a10f62b744ef5a5e7ace2addedf26b1accd54c022a330c3d878f83647e3f8bba9a2d024ab22246fbb4dfbfb625f2314d9d2534aa96c17d96e
|
data/.editorconfig
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# http://editorconfig.org
|
2
|
+
root = true
|
3
|
+
|
4
|
+
[*]
|
5
|
+
indent_style = space
|
6
|
+
indent_size = 2
|
7
|
+
end_of_line = lf
|
8
|
+
charset = utf-8
|
9
|
+
trim_trailing_whitespace = true
|
10
|
+
insert_final_newline = true
|
11
|
+
|
12
|
+
[*.{sh,md}]
|
13
|
+
indent_size = 4
|
14
|
+
max_line_length = 0
|
15
|
+
trim_trailing_whitespace = false
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
require: rubocop-rspec
|
2
|
+
|
3
|
+
AllCops:
|
4
|
+
TargetRubyVersion: 2.5
|
5
|
+
|
6
|
+
Exclude:
|
7
|
+
- 'bin/*'
|
8
|
+
- 'vendor/**/*'
|
9
|
+
|
10
|
+
Style/Documentation:
|
11
|
+
# Skips checking to make sure top level modules / classes have a comment.
|
12
|
+
Enabled: false
|
13
|
+
|
14
|
+
Style/ClassAndModuleChildren:
|
15
|
+
# Skips checking the style of children definitions at classes and modules.
|
16
|
+
Enabled: false
|
17
|
+
|
18
|
+
Metrics/LineLength:
|
19
|
+
# Commonly used screens these days easily fit more than 80 characters.
|
20
|
+
Max: 120
|
21
|
+
Exclude:
|
22
|
+
- 'spec/**/*'
|
23
|
+
|
24
|
+
Metrics/AbcSize:
|
25
|
+
# 15 is sometimes difficult to stay under.
|
26
|
+
Max: 20
|
27
|
+
|
28
|
+
Metrics/MethodLength:
|
29
|
+
# Too short methods lead to extraction of single-use methods, which can make
|
30
|
+
# the code easier to read (by naming things), but can also clutter the class
|
31
|
+
Max: 25
|
32
|
+
|
33
|
+
Metrics/BlockLength:
|
34
|
+
Exclude:
|
35
|
+
- 'spec/**/*'
|
36
|
+
|
37
|
+
Layout/SpaceAroundEqualsInParameterDefault:
|
38
|
+
# No space makes the method definition shorter and differentiates
|
39
|
+
# from a regular assignment.
|
40
|
+
EnforcedStyle: no_space
|
41
|
+
|
42
|
+
Style/SymbolArray:
|
43
|
+
# We do not need to support Ruby 1.9, so this is good to use.
|
44
|
+
Enabled: true
|
45
|
+
|
46
|
+
Style/PercentLiteralDelimiters:
|
47
|
+
# Because percent literals are closer to method calls, use parenthesis.
|
48
|
+
PreferredDelimiters:
|
49
|
+
default: ()
|
50
|
+
'%i': '()'
|
51
|
+
'%w': '()'
|
52
|
+
|
53
|
+
RSpec/NestedGroups:
|
54
|
+
Max: 5
|
55
|
+
|
56
|
+
Naming/FileName:
|
57
|
+
Exclude:
|
58
|
+
- 'lib/sidekiq-control.rb'
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
sidekiq-control
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.6.2
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at afrase91@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Aaron Frase
|
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,51 @@
|
|
1
|
+
# Sidekiq::Control
|
2
|
+
|
3
|
+
This gem adds a new tab to Sidekiq to allow starting jobs from the web UI (usually found at `/web/admin/sidekiq/control`)
|
4
|
+
|
5
|
+

|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'sidekiq-control'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install sidekiq-control
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
Including the gem automatically adds the functionality, no further configuration is necessary!
|
26
|
+
|
27
|
+
To include in dev/staging environment specify in your Gemfile
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
group :staging, :development do
|
31
|
+
gem 'sidekiq-control', github: 'rvshare/sidekiq-control'
|
32
|
+
end
|
33
|
+
```
|
34
|
+
|
35
|
+
## Development
|
36
|
+
|
37
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
38
|
+
|
39
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
40
|
+
|
41
|
+
## Contributing
|
42
|
+
|
43
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/rvshare/sidekiq-control. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
44
|
+
|
45
|
+
## License
|
46
|
+
|
47
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
48
|
+
|
49
|
+
## Code of Conduct
|
50
|
+
|
51
|
+
Everyone interacting in the Sidekiq::Control project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/rvshare/sidekiq-control/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'yard'
|
4
|
+
require 'bundler/gem_tasks'
|
5
|
+
require 'rspec/core/rake_task'
|
6
|
+
require 'rubocop/rake_task'
|
7
|
+
require 'sidekiq/control/version'
|
8
|
+
|
9
|
+
RSpec::Core::RakeTask.new
|
10
|
+
|
11
|
+
RuboCop::RakeTask.new do |task|
|
12
|
+
task.requires << 'rubocop-rspec'
|
13
|
+
end
|
14
|
+
|
15
|
+
YARD::Rake::YardocTask.new do |task|
|
16
|
+
task.options += ['--title', "Sidekiq Control #{Sidekiq::Control::VERSION} Documentation"]
|
17
|
+
task.options += ['--protected']
|
18
|
+
task.options += ['--no-private']
|
19
|
+
task.stats_options = ['--list-undoc']
|
20
|
+
|
21
|
+
# has to be last
|
22
|
+
extra_files = %w(CODE_OF_CONDUCT.md LICENSE.txt)
|
23
|
+
task.options += ['-'] + extra_files
|
24
|
+
end
|
25
|
+
|
26
|
+
task default: %i(rubocop spec)
|
data/bin/console
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'sidekiq/control'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
require 'pry'
|
10
|
+
Pry.start
|
data/bin/setup
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Sidekiq
|
4
|
+
module Control
|
5
|
+
class Configuration
|
6
|
+
attr_writer :jobs
|
7
|
+
attr_accessor :ignored_classes
|
8
|
+
|
9
|
+
DEFAULT_IGNORED_CLASSES = %w(
|
10
|
+
ApplicationJob
|
11
|
+
Sidekiq::Batch::Callback
|
12
|
+
Rollbar::Delay::Sidekiq
|
13
|
+
Searchkick::ReindexV2Job
|
14
|
+
Searchkick::BulkReindexJob
|
15
|
+
Searchkick::ProcessBatchJob
|
16
|
+
Searchkick::ProcessQueueJob
|
17
|
+
ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper
|
18
|
+
ActiveStorage::AnalyzeJob
|
19
|
+
ActiveStorage::PurgeJob
|
20
|
+
).freeze
|
21
|
+
|
22
|
+
def initialize
|
23
|
+
self.ignored_classes = DEFAULT_IGNORED_CLASSES
|
24
|
+
end
|
25
|
+
|
26
|
+
def jobs
|
27
|
+
@jobs ||= application_jobs.sort_by(&:name)
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def application_jobs
|
33
|
+
rails_eager_load
|
34
|
+
(sidekiq_jobs + active_jobs).select(&method(:select_class?))
|
35
|
+
end
|
36
|
+
|
37
|
+
def select_class?(klass)
|
38
|
+
return if Sidekiq::Control.config.ignored_classes.include?(klass.name)
|
39
|
+
|
40
|
+
klass.public_instance_methods(false).include?(:perform)
|
41
|
+
end
|
42
|
+
|
43
|
+
def sidekiq_jobs
|
44
|
+
return [] unless defined?(::Sidekiq::Worker)
|
45
|
+
|
46
|
+
find_descendants_of(::Sidekiq::Worker)
|
47
|
+
end
|
48
|
+
|
49
|
+
def active_jobs
|
50
|
+
return [] unless defined?(::ActiveJob::Base)
|
51
|
+
|
52
|
+
find_descendants_of(::ActiveJob::Base)
|
53
|
+
end
|
54
|
+
|
55
|
+
def find_descendants_of(obj)
|
56
|
+
ObjectSpace.each_object(Class).select(&obj.method(:>))
|
57
|
+
end
|
58
|
+
|
59
|
+
def rails_eager_load
|
60
|
+
::Rails.application.eager_load! if defined?(::Rails) && !::Rails.env.production?
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'sidekiq/control/web/helpers'
|
4
|
+
|
5
|
+
module Sidekiq
|
6
|
+
module Control
|
7
|
+
module Web
|
8
|
+
module Application
|
9
|
+
WEB_PATH = File.expand_path(File.join('..', '..', '..', '..', 'web'), __dir__)
|
10
|
+
VIEW_PATH = File.join(WEB_PATH, 'views')
|
11
|
+
LOCALES_PATH = File.join(WEB_PATH, 'locales')
|
12
|
+
|
13
|
+
# @param [Sidekiq::WebApplication] app
|
14
|
+
def self.registered(app) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
|
15
|
+
app.helpers(Helpers)
|
16
|
+
|
17
|
+
app.get('/control') do
|
18
|
+
@jobs = Sidekiq::Control.jobs
|
19
|
+
erb(File.read(File.join(VIEW_PATH, 'index.erb')))
|
20
|
+
end
|
21
|
+
|
22
|
+
app.get('/control/:name') do
|
23
|
+
@job = Sidekiq::Control.jobs.find { |job| job.name == params[:name] }
|
24
|
+
erb(File.read(File.join(VIEW_PATH, 'show_job.erb')))
|
25
|
+
end
|
26
|
+
|
27
|
+
app.post('/control') do
|
28
|
+
job = Sidekiq::Control.jobs.find { |j| j.name == params[:job_name] }
|
29
|
+
begin
|
30
|
+
case params[:submit]
|
31
|
+
when t('Run')
|
32
|
+
job.trigger(get_job_params(job, params), params[:job_queue])
|
33
|
+
when t('Schedule')
|
34
|
+
job.trigger_in(params[:perform_in].to_f, get_job_params(job, params), params[:job_queue])
|
35
|
+
when t('Perform')
|
36
|
+
job.job.send(params[:perform_method])
|
37
|
+
end
|
38
|
+
|
39
|
+
redirect(url_path('control'))
|
40
|
+
rescue StandardError => e
|
41
|
+
@error = e
|
42
|
+
erb(File.read(File.join(VIEW_PATH, 'error.erb')))
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Sidekiq
|
4
|
+
module Control
|
5
|
+
module Web
|
6
|
+
module Helpers
|
7
|
+
def link_to(path, text, options={})
|
8
|
+
%(<a href="#{url_path(path)}"#{to_attributes(options)}>#{text}</a>)
|
9
|
+
end
|
10
|
+
|
11
|
+
def url_path(path)
|
12
|
+
"#{root_path}#{path.sub(%r{^/}, '')}"
|
13
|
+
end
|
14
|
+
|
15
|
+
def display_params(params)
|
16
|
+
params.map(&:name).reject { |n| n.start_with?('_') || n.empty? }.tap do |p|
|
17
|
+
return 'None' if p.empty?
|
18
|
+
end.join(', ')
|
19
|
+
end
|
20
|
+
|
21
|
+
def get_job_params(job, params)
|
22
|
+
return [] if params[:perform].nil?
|
23
|
+
|
24
|
+
ParamsParser.values(job, params[:perform])
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def to_attributes(data)
|
30
|
+
# add a space before attributes since this is called without a space between the tag name and the attributes.
|
31
|
+
" #{data.map { |k, v| "#{k}=\"#{v.is_a?(Array) ? v.join(' ') : v}\"" }.join(' ')}" unless data.empty?
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Sidekiq
|
4
|
+
module Control
|
5
|
+
module Web
|
6
|
+
class ParamsParser
|
7
|
+
attr_reader :job
|
8
|
+
attr_reader :params
|
9
|
+
|
10
|
+
def self.values(job, params)
|
11
|
+
new(job, params).values
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize(job, params)
|
15
|
+
@job = job
|
16
|
+
@params = params
|
17
|
+
end
|
18
|
+
|
19
|
+
def values
|
20
|
+
job.params.map do |param|
|
21
|
+
param.value = extract_value(param.name)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def extract_value(param_name)
|
28
|
+
return if params[param_name].nil?
|
29
|
+
|
30
|
+
cleanup(params[param_name])
|
31
|
+
end
|
32
|
+
|
33
|
+
def cleanup(value)
|
34
|
+
value unless value.to_s.casecmp('nil').zero? || value.to_s.strip.empty?
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Sidekiq
|
4
|
+
module Control
|
5
|
+
module Worker
|
6
|
+
class Instance
|
7
|
+
UnsupportedJobType = Class.new(StandardError)
|
8
|
+
|
9
|
+
attr_reader :job
|
10
|
+
|
11
|
+
# @param [Class] job
|
12
|
+
def initialize(job)
|
13
|
+
@job = job
|
14
|
+
end
|
15
|
+
|
16
|
+
def name
|
17
|
+
job.name
|
18
|
+
end
|
19
|
+
|
20
|
+
def params
|
21
|
+
@params ||= worker_params.map { |e| Param.new(*e) }
|
22
|
+
end
|
23
|
+
|
24
|
+
def queue
|
25
|
+
@queue ||= sidekiq_job? ? job.get_sidekiq_options['queue'] : job.queue_name
|
26
|
+
end
|
27
|
+
|
28
|
+
def other_perform_methods
|
29
|
+
@other_perform_methods ||= job.singleton_methods(false).select { |m| m.to_s.start_with?('perform') }
|
30
|
+
end
|
31
|
+
|
32
|
+
def trigger(params, job_queue=nil)
|
33
|
+
trigger_in(0, params, job_queue)
|
34
|
+
end
|
35
|
+
|
36
|
+
def trigger_in(seconds, params, job_queue=nil)
|
37
|
+
if sidekiq_job?
|
38
|
+
Sidekiq::Client.enqueue_to_in(job_queue || queue, seconds, job, *params)
|
39
|
+
elsif active_job?
|
40
|
+
job.set(wait: seconds, queue: job_queue || queue).perform_later(*params)
|
41
|
+
else
|
42
|
+
raise UnsupportedJobType
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def sidekiq_job?
|
49
|
+
job <= ::Sidekiq::Worker
|
50
|
+
end
|
51
|
+
|
52
|
+
def active_job?
|
53
|
+
job <= ::ActiveJob::Base
|
54
|
+
end
|
55
|
+
|
56
|
+
def worker_params
|
57
|
+
job.instance_method(:perform).parameters
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Sidekiq
|
4
|
+
module Control
|
5
|
+
module Worker
|
6
|
+
class Param
|
7
|
+
TYPE_MAP = { req: 'required', opt: 'optional' }.freeze
|
8
|
+
|
9
|
+
attr_reader :type
|
10
|
+
attr_reader :name
|
11
|
+
attr_reader :value
|
12
|
+
|
13
|
+
def initialize(type, name=nil)
|
14
|
+
@type = type
|
15
|
+
@name = name.to_s
|
16
|
+
end
|
17
|
+
|
18
|
+
def value=(value)
|
19
|
+
raise ArgumentError if required? && value.nil?
|
20
|
+
|
21
|
+
@value = value
|
22
|
+
end
|
23
|
+
|
24
|
+
def type_name
|
25
|
+
TYPE_MAP[@type]
|
26
|
+
end
|
27
|
+
|
28
|
+
def required?
|
29
|
+
@type == :req
|
30
|
+
end
|
31
|
+
|
32
|
+
def optional?
|
33
|
+
!required?
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'sidekiq/web'
|
4
|
+
|
5
|
+
require 'sidekiq/control/version'
|
6
|
+
require 'sidekiq/control/configuration'
|
7
|
+
require 'sidekiq/control/worker/instance'
|
8
|
+
require 'sidekiq/control/worker/param'
|
9
|
+
require 'sidekiq/control/web/application'
|
10
|
+
require 'sidekiq/control/web/params_parser'
|
11
|
+
require 'sidekiq/control/web/helpers'
|
12
|
+
|
13
|
+
module Sidekiq
|
14
|
+
module Control
|
15
|
+
class << self
|
16
|
+
attr_writer :configuration
|
17
|
+
|
18
|
+
def configuration
|
19
|
+
@configuration ||= Configuration.new
|
20
|
+
end
|
21
|
+
alias config configuration
|
22
|
+
|
23
|
+
def configure
|
24
|
+
yield configuration
|
25
|
+
end
|
26
|
+
|
27
|
+
def jobs
|
28
|
+
@jobs ||= configuration.jobs.map { |job| Worker::Instance.new(job) }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
::Sidekiq::Web.register(Web::Application)
|
33
|
+
::Sidekiq::Web.settings.locales << Web::Application::LOCALES_PATH
|
34
|
+
::Sidekiq::Web.tabs['Control'] = 'control'
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'sidekiq/control/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'sidekiq-control'
|
9
|
+
spec.version = Sidekiq::Control::VERSION
|
10
|
+
spec.authors = ['Aaron Frase']
|
11
|
+
spec.email = ['afrase91@gmail.com']
|
12
|
+
|
13
|
+
spec.summary = 'Manually trigger background jobs'
|
14
|
+
spec.description = spec.summary
|
15
|
+
spec.homepage = 'https://github.com/afrase/sidekiq-control'
|
16
|
+
spec.license = 'MIT'
|
17
|
+
|
18
|
+
# Specify which files should be added to the gem when it is released.
|
19
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
20
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
21
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
22
|
+
end
|
23
|
+
spec.bindir = 'exe'
|
24
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
25
|
+
spec.require_paths = ['lib']
|
26
|
+
|
27
|
+
spec.metadata['yard.run'] = 'yri' # use "yard" to build full HTML docs.
|
28
|
+
|
29
|
+
spec.add_dependency 'sidekiq', '~> 6.0'
|
30
|
+
|
31
|
+
spec.add_development_dependency 'bundler', '~> 2.0'
|
32
|
+
spec.add_development_dependency 'pry', '~> 0.11'
|
33
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
34
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
35
|
+
spec.add_development_dependency 'rspec_junit_formatter', '~> 0.3'
|
36
|
+
spec.add_development_dependency 'rubocop', '~> 0.52'
|
37
|
+
spec.add_development_dependency 'rubocop-rspec', '~> 1.22', '>= 1.22.2'
|
38
|
+
spec.add_development_dependency 'simplecov', '~> 0.16.1'
|
39
|
+
spec.add_development_dependency 'yard', '~> 0.9.12'
|
40
|
+
end
|
data/web/locales/en.yml
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
en:
|
2
|
+
Control: Control
|
3
|
+
Jobs: Jobs
|
4
|
+
JobName: Job name
|
5
|
+
Run: Run
|
6
|
+
OtherMethods: Other Methods
|
7
|
+
Perform: Perform
|
8
|
+
Name: Name
|
9
|
+
Parameters: Parameters
|
10
|
+
Actions: Actions
|
11
|
+
Queue: Queue
|
12
|
+
PerformIn: Perform in
|
13
|
+
seconds: seconds
|
14
|
+
Error: Error
|
15
|
+
ErrorClass: Error Class
|
16
|
+
ErrorMessage: Error Message
|
data/web/views/error.erb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
<h3><%= t('Error') %></h3>
|
2
|
+
<div class="table_container">
|
3
|
+
<table class="error table table-bordered table-striped">
|
4
|
+
<tbody>
|
5
|
+
<tr>
|
6
|
+
<th><%= t('ErrorClass') %></th>
|
7
|
+
<td>
|
8
|
+
<code><%= @error.class %></code>
|
9
|
+
</td>
|
10
|
+
</tr>
|
11
|
+
<tr>
|
12
|
+
<th><%= t('ErrorMessage') %></th>
|
13
|
+
<td><%= h(@error.message) %></td>
|
14
|
+
</tr>
|
15
|
+
<tr>
|
16
|
+
<th><%= t('ErrorBacktrace') %></th>
|
17
|
+
<td>
|
18
|
+
<code><%= @error.backtrace.join('<br/>') %></code>
|
19
|
+
</td>
|
20
|
+
</tr>
|
21
|
+
</tbody>
|
22
|
+
</table>
|
23
|
+
</div>
|
data/web/views/index.erb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
<div class="row header">
|
2
|
+
<div class="col-sm-7">
|
3
|
+
<h3><%= t('Jobs') %></h3>
|
4
|
+
</div>
|
5
|
+
</div>
|
6
|
+
|
7
|
+
<div class="table_container">
|
8
|
+
<table class="table table-hover table-bordered table-striped table-white">
|
9
|
+
<thead>
|
10
|
+
<tr>
|
11
|
+
<th><%= t('Name') %></th>
|
12
|
+
<th><%= t('Parameters') %></th>
|
13
|
+
<th><%= t('Actions') %></th>
|
14
|
+
</tr>
|
15
|
+
</thead>
|
16
|
+
<tbody>
|
17
|
+
<% @jobs.each do |job| %>
|
18
|
+
<tr>
|
19
|
+
<td width="40%">
|
20
|
+
<%= job.name %>
|
21
|
+
</td>
|
22
|
+
<td width="50%">
|
23
|
+
<%= display_params(job.params) %>
|
24
|
+
</td>
|
25
|
+
<td width="10%">
|
26
|
+
<%= link_to("/control/#{job.name}", t('Perform'), class: 'btn btn-danger btn-xs', style: 'color:white;') %>
|
27
|
+
</td>
|
28
|
+
</tr>
|
29
|
+
<% end %>
|
30
|
+
</tbody>
|
31
|
+
</table>
|
32
|
+
</div>
|
@@ -0,0 +1,68 @@
|
|
1
|
+
<header class="row">
|
2
|
+
<div class="col-sm-5">
|
3
|
+
<h3><%= t('Control') %></h3>
|
4
|
+
</div>
|
5
|
+
</header>
|
6
|
+
|
7
|
+
<form action="<%= url_path('control') %>" method="post">
|
8
|
+
<%= csrf_tag %>
|
9
|
+
|
10
|
+
<div class="panel panel-default">
|
11
|
+
<div class="panel-heading">
|
12
|
+
<h3 class="panel-title">
|
13
|
+
<%= t('Perform') %>
|
14
|
+
</h3>
|
15
|
+
</div>
|
16
|
+
|
17
|
+
<div class="panel-body">
|
18
|
+
<div class="form-group">
|
19
|
+
<label for="job_name"><%= t('JobName') %></label>
|
20
|
+
<input type="text" class="form-control" id="job_name" name="job_name" value="<%= @job.name %>" readonly/>
|
21
|
+
</div>
|
22
|
+
|
23
|
+
<div class="form-group">
|
24
|
+
<label for="job_queue"><%= t('Queue') %></label>
|
25
|
+
<input type="text" class="form-control" id="job_queue" name="job_queue" value="<%= @job.queue %>">
|
26
|
+
</div>
|
27
|
+
|
28
|
+
<% @job.params.reject { |p| p.name.start_with?('_') }.each do |param| %>
|
29
|
+
<div class="form-group">
|
30
|
+
<label for="<%= param.name %>">
|
31
|
+
<%= param.name %><% if param.required? %><span style="color:red;font-size:small;">*</span><% end %>
|
32
|
+
</label>
|
33
|
+
<input class="form-control" id="<%= param.name %>" name="perform[<%= param.name %>]"/>
|
34
|
+
</div>
|
35
|
+
<% end %>
|
36
|
+
|
37
|
+
<input type="submit" class="btn btn-default" name="submit" value="<%= t('Run') %>"/>
|
38
|
+
</div>
|
39
|
+
</div>
|
40
|
+
|
41
|
+
<div class="panel">
|
42
|
+
<div class="panel-body">
|
43
|
+
<div class="form-group">
|
44
|
+
<label for="perform_in"><%= t('PerformIn') %></label>
|
45
|
+
<input class="form-control" id="perform_in" name="perform_in" placeholder="<%= t('seconds') %>"/>
|
46
|
+
</div>
|
47
|
+
|
48
|
+
<input type="submit" class="btn btn-danger" name="submit" value="<%= t('Schedule') %>"/>
|
49
|
+
</div>
|
50
|
+
</div>
|
51
|
+
|
52
|
+
<% if @job.other_perform_methods.any? %>
|
53
|
+
<div class="panel">
|
54
|
+
<div class="panel-body">
|
55
|
+
<div class="form-group">
|
56
|
+
<label for="perform_method"><%= t('OtherMethods') %></label>
|
57
|
+
<select name="perform_method" id="perform_method" class="form-control">
|
58
|
+
<% @job.other_perform_methods.each do |meth| %>
|
59
|
+
<option value="<%= meth %>"><%= meth %></option>
|
60
|
+
<% end %>
|
61
|
+
</select>
|
62
|
+
</div>
|
63
|
+
|
64
|
+
<input type="submit" class="btn btn-danger" name="submit" value="<%= t('Perform') %>"/>
|
65
|
+
</div>
|
66
|
+
</div>
|
67
|
+
<% end %>
|
68
|
+
</form>
|
metadata
ADDED
@@ -0,0 +1,217 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sidekiq-control
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.10
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Aaron Frase
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-10-14 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: '6.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '6.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.11'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.11'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec_junit_formatter
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.3'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.3'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rubocop
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.52'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.52'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rubocop-rspec
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '1.22'
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: 1.22.2
|
121
|
+
type: :development
|
122
|
+
prerelease: false
|
123
|
+
version_requirements: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - "~>"
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '1.22'
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: 1.22.2
|
131
|
+
- !ruby/object:Gem::Dependency
|
132
|
+
name: simplecov
|
133
|
+
requirement: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - "~>"
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: 0.16.1
|
138
|
+
type: :development
|
139
|
+
prerelease: false
|
140
|
+
version_requirements: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - "~>"
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: 0.16.1
|
145
|
+
- !ruby/object:Gem::Dependency
|
146
|
+
name: yard
|
147
|
+
requirement: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - "~>"
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: 0.9.12
|
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.12
|
159
|
+
description: Manually trigger background jobs
|
160
|
+
email:
|
161
|
+
- afrase91@gmail.com
|
162
|
+
executables: []
|
163
|
+
extensions: []
|
164
|
+
extra_rdoc_files: []
|
165
|
+
files:
|
166
|
+
- ".editorconfig"
|
167
|
+
- ".gitignore"
|
168
|
+
- ".rspec"
|
169
|
+
- ".rubocop.yml"
|
170
|
+
- ".ruby-gemset"
|
171
|
+
- ".ruby-version"
|
172
|
+
- CODE_OF_CONDUCT.md
|
173
|
+
- Gemfile
|
174
|
+
- LICENSE.txt
|
175
|
+
- README.md
|
176
|
+
- Rakefile
|
177
|
+
- bin/console
|
178
|
+
- bin/setup
|
179
|
+
- lib/sidekiq-control.rb
|
180
|
+
- lib/sidekiq/control.rb
|
181
|
+
- lib/sidekiq/control/configuration.rb
|
182
|
+
- lib/sidekiq/control/version.rb
|
183
|
+
- lib/sidekiq/control/web/application.rb
|
184
|
+
- lib/sidekiq/control/web/helpers.rb
|
185
|
+
- lib/sidekiq/control/web/params_parser.rb
|
186
|
+
- lib/sidekiq/control/worker/instance.rb
|
187
|
+
- lib/sidekiq/control/worker/param.rb
|
188
|
+
- sidekiq-control.gemspec
|
189
|
+
- web/locales/en.yml
|
190
|
+
- web/views/error.erb
|
191
|
+
- web/views/index.erb
|
192
|
+
- web/views/show_job.erb
|
193
|
+
homepage: https://github.com/afrase/sidekiq-control
|
194
|
+
licenses:
|
195
|
+
- MIT
|
196
|
+
metadata:
|
197
|
+
yard.run: yri
|
198
|
+
post_install_message:
|
199
|
+
rdoc_options: []
|
200
|
+
require_paths:
|
201
|
+
- lib
|
202
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
203
|
+
requirements:
|
204
|
+
- - ">="
|
205
|
+
- !ruby/object:Gem::Version
|
206
|
+
version: '0'
|
207
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
208
|
+
requirements:
|
209
|
+
- - ">="
|
210
|
+
- !ruby/object:Gem::Version
|
211
|
+
version: '0'
|
212
|
+
requirements: []
|
213
|
+
rubygems_version: 3.0.6
|
214
|
+
signing_key:
|
215
|
+
specification_version: 4
|
216
|
+
summary: Manually trigger background jobs
|
217
|
+
test_files: []
|