forked from ogom/redmine_sidekiq
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit ff1b8be
Showing
17 changed files
with
228 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/config/*.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
gem 'sidekiq', '2.10.0' | ||
gem 'slim' | ||
gem 'sinatra', '>= 1.3.0', :require => nil | ||
|
||
gem 'sidekiq-status' | ||
gem 'sidekiq-unique-jobs' | ||
gem 'sidekiq-failures' | ||
|
||
gem 'clockwork' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
Redmine Sidekiq | ||
=============== | ||
|
||
Background jobs will use the [Sidekiq](https://github.com/mperham/sidekiq) on Redmine. | ||
|
||
## Features | ||
|
||
* Administrator can use the Sidekiq Web UI from the top menu. | ||
* Add to autoload_paths of the Plugin '/app/workers'. | ||
* Add Middleware of 'sidekiq-status'. | ||
|
||
## Installation | ||
|
||
``` | ||
$ git clone https://github.com/ogom/redmine_sidekiq ./plugins/redmine_sidekiq | ||
``` | ||
|
||
## Example | ||
|
||
Example of Sidekiq worker. | ||
|
||
``` | ||
./plugins/redmine_sidekiq/workers/sandbox_worker.rb | ||
``` | ||
|
||
## Web UI | ||
Enqueue from the Web UI. | ||
|
||
``` | ||
http://[redmine]/sidekiq/sandbox | ||
``` | ||
|
||
## CLI | ||
|
||
Enqueue from the command line. | ||
|
||
``` | ||
$ script/rails runner 'SandboxWorker.perform_async' | ||
``` | ||
|
||
## License | ||
|
||
* MIT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
class SidekiqSandboxController < ApplicationController | ||
unloadable | ||
before_filter :require_admin | ||
|
||
def index | ||
@stats = Sidekiq::Stats.new | ||
end | ||
|
||
def perform_async | ||
name = params['name'] | ||
count = params['count'] | ||
jid = SandboxWorker.perform_async(name, count) | ||
flash[:notice] = "Enqueued job id: #{jid}" if jid | ||
redirect_to :action => 'index' | ||
end | ||
|
||
def perform_in | ||
interval = params['interval'].to_i ||= 2 | ||
jid = SandboxWorker.perform_in(interval.minute) | ||
flash[:notice] = "Enqueued job id: #{jid}" if jid | ||
redirect_to :action => 'index' | ||
end | ||
|
||
def perform_at | ||
interval = params['interval'].to_i ||= 2 | ||
jid = SandboxWorker.perform_at(interval.minute.from_now) | ||
flash[:notice] = "Enqueued job id: #{jid}" if jid | ||
redirect_to :action => 'index' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module SidekiqSandboxHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<h2>Sidekiq Sandbox</h2> | ||
|
||
<hr> | ||
|
||
<h3>Stats</h3> | ||
|
||
<p>stats = Sidekiq::Stats.new</p> | ||
|
||
<h4>The number of jobs that have been processed.</h4> | ||
<p>stats.processed # => <%= @stats.processed %></p> | ||
|
||
<h4>The number of jobs that have failed.</h4> | ||
<p>stats.failed # => <%= @stats.failed %></p> | ||
|
||
<h4>The queues with name and number enqueued.</h4> | ||
<p>stats.queues # => <%= @stats.queues %></p> | ||
|
||
<h4>The number of jobs enqueued in all queues (does NOT include retries and scheduled jobs).</h4> | ||
<p>stats.enqueued # => <%= @stats.enqueued %></p> | ||
|
||
<hr> | ||
|
||
<h3>Jobs</h3> | ||
|
||
<h4>The standard.</h4> | ||
<p><%= link_to('perform_async(*args)', sidekiq_sandbox_perform_async_path, method: :post) %></p> | ||
|
||
<h4>The Scheduled Jobs by interval.</h4> | ||
<p><%= link_to('perform_in(interval, *args)', sidekiq_sandbox_perform_in_path(interval: 1), method: :post) %></p> | ||
|
||
<h4>The Scheduled Jobs by timestamp.</h4> | ||
<p><%= link_to('perform_at(timestamp, *args)', sidekiq_sandbox_perform_at_path(interval: 1), method: :post) %></p> | ||
|
||
<h4>The job will fail.</h4> | ||
<p><%= link_to('perform_async()', sidekiq_sandbox_perform_async_path(name: :failed), method: :post) %></p> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class SandboxWorker | ||
include Sidekiq::Worker | ||
include Sidekiq::Status::Worker | ||
sidekiq_options retry: 2, unique: true | ||
|
||
def perform(name=nil, count=nil) | ||
puts 'Doing sandbox work' | ||
raise 'Failed sandbox work' if name == 'failed' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
en: | ||
Sidekiq: 'Sidekiq' | ||
Failures: 'Failures' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
ja: | ||
Sidekiq: 'Sidekiq' | ||
Failures: 'Failures' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
require 'sidekiq/web' | ||
require 'redmine_sidekiq/admin_constraint' | ||
|
||
RedmineApp::Application.routes.draw do | ||
mount Sidekiq::Web => '/sidekiq', :constraints => RedmineSidekiq::AdminConstraint.new | ||
|
||
match '/sidekiq/sandbox', to: 'sidekiq_sandbox#index', via: :get | ||
match '/sidekiq/sandbox/perform_async', to: 'sidekiq_sandbox#perform_async', via: :post | ||
match '/sidekiq/sandbox/perform_in', to: 'sidekiq_sandbox#perform_in', via: :post | ||
match '/sidekiq/sandbox/perform_at', to: 'sidekiq_sandbox#perform_at', via: :post | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
development: | ||
redis: | ||
url: redis://localhost:6379/8 | ||
namespace: mynamespace | ||
status: | ||
expiration: 30 | ||
|
||
production: | ||
redis: | ||
url: redis://localhost:6379/8 | ||
namespace: mynamespace | ||
status: | ||
expiration: 30 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
require 'redmine_sidekiq/configure' | ||
require 'redmine_sidekiq/rails' | ||
|
||
Redmine::Plugin.register :redmine_sidekiq do | ||
name 'Redmine Sidekiq plugin' | ||
description 'This is a Sidekiq plugin for Redmine' | ||
version '0.0.1' | ||
url 'https://github.com/ogom/redmine_sidekiq' | ||
author_url 'mailto:[email protected]' | ||
author 'ogom' | ||
|
||
menu :top_menu, :sidekiq, '/sidekiq', :if => Proc.new {User.current.admin} | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module RedmineSidekiq | ||
class AdminConstraint | ||
def matches?(request) | ||
User.current.admin | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
require 'sidekiq' | ||
require 'sidekiq-status' | ||
|
||
module RedmineSidekiq | ||
class Configure | ||
file = File.join(Rails.root, 'plugins/redmine_sidekiq/config/sidekiq.yml') | ||
config = YAML.load_file(file)[Rails.env] | ||
redis_conf = config['redis'].symbolize_keys | ||
st_expire = config['status']['expiration'].to_i | ||
|
||
Sidekiq.configure_server do |config| | ||
config.redis = redis_conf | ||
config.server_middleware do |chain| | ||
chain.add Sidekiq::Status::ServerMiddleware, expiration: st_expire.minutes | ||
end | ||
end | ||
|
||
Sidekiq.configure_client do |config| | ||
config.redis = redis_conf | ||
config.client_middleware do |chain| | ||
chain.add Sidekiq::Status::ClientMiddleware | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module RedmineSidekiq | ||
class Rails | ||
Dir.glob(File.join(Redmine::Plugin.directory, '*')).sort.each do |directory| | ||
if File.directory?(directory) | ||
workers = File.join(directory, "app", "workers") | ||
if File.directory?(workers) | ||
ActiveSupport::Dependencies.autoload_paths += [workers] | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
require File.expand_path('../../test_helper', __FILE__) | ||
|
||
class SidekiqSandboxControllerTest < ActionController::TestCase | ||
# Replace this with your real tests. | ||
def test_truth | ||
assert true | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Load the Redmine helper | ||
require File.expand_path(File.dirname(__FILE__) + '/../../../test/test_helper') |