Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
...
Checking mergeability… Don’t worry, you can still create the pull request.
  • 19 commits
  • 5 files changed
  • 0 commit comments
  • 2 contributors
Showing with 68 additions and 2 deletions.
  1. +2 −0 .gitignore
  2. +14 −0 README.md
  3. +40 −0 lib/sidekiq/cli.rb
  4. +11 −1 lib/sidekiq/processor.rb
  5. +1 −1 sidekiq.gemspec
View
2 .gitignore
@@ -9,3 +9,5 @@ coverage/
vendor/
.bundle/
.sass-cache/
+
+*.gem
View
14 README.md
@@ -1,6 +1,20 @@
Sidekiq
==============
+Some background information: I created this fork because I have need to enforce single threaded execution on the main thread. This is due to legacy API limitations. This implementation uses the Monitor mix-in to handle enforcement of single-threaded worker execution.
+
+This fork adds a special -si or --singlethreaded command line option that forces one thread of execution. It also forces each item to performed on the main thread. This was built and tested on JRuby 1.7.6 and tested on Windows only. Although I don't see any reason why this wouldn't run on other Ruby distros and operating systems.
+
+Build/Install Instructions: (Make sure to remove any existing .gem files from the build directory.)
+jruby -S gem build sidekiq.gemspec
+jruby -S gem install sidekiq-2.15.2.gem
+
+Run:
+jruby -S sidekiq -c 1 -si
+
+Or: Use normally
+jruby -S sidekiq -c 10
+
[![Gem Version](https://badge.fury.io/rb/sidekiq.png)](https://rubygems.org/gems/sidekiq) [![Code Climate](https://codeclimate.com/github/mperham/sidekiq.png)](https://codeclimate.com/github/mperham/sidekiq) [![Build Status](https://travis-ci.org/mperham/sidekiq.png)](https://travis-ci.org/mperham/sidekiq) [![Coverage Status](https://coveralls.io/repos/mperham/sidekiq/badge.png?branch=master)](https://coveralls.io/r/mperham/sidekiq)
View
40 lib/sidekiq/cli.rb
@@ -7,6 +7,7 @@
require 'sidekiq'
require 'sidekiq/util'
+require 'monitor'
module Sidekiq
# We are shutting down Sidekiq but what about workers that
@@ -45,9 +46,15 @@ def parse(args=ARGV)
def run
self_read, self_write = IO.pipe
+ # For Windows (MRI) remove USR1, USR2, and TTIN.
+
%w(INT TERM USR1 USR2 TTIN).each do |sig|
trap sig do
self_write.puts(sig)
+ handle_signal(sig)
+ logger.info 'Shutting down'
+ launcher.stop
+ exit(0)
end
end
@@ -69,6 +76,35 @@ def run
RubyProf.start
end
launcher.run
+ $single_threaded = options[:singlethreaded]
+ if options[:singlethreaded]
+ $monitor = Monitor.new
+ $queue_wait_condition = $monitor.new_cond
+
+=begin
+ Thread.new do
+ while readable_io = IO.select([IO.pipe])
+ signal = readable_io.first[0].gets.strip
+ handle_signal(signal)
+ end
+ end
+=end
+ $worker_args = nil
+ #$sync_queue = java.util.concurrent.SynchronousQueue.new
+ $worker = nil
+ while true
+ $monitor.synchronize do
+ $queue_wait_condition.wait_while { $worker_args.nil? }
+ $worker.perform(*$worker_args)
+ $worker_args = nil
+ end
+ end
+ else
+ while readable_io = IO.select([self_read])
+ signal = readable_io.first[0].gets.strip
+ handle_signal(signal)
+ end
+ end
while readable_io = IO.select([self_read])
signal = readable_io.first[0].gets.strip
@@ -252,6 +288,10 @@ def parse_options(argv)
opts[:index] = Integer(arg.match(/\d+/)[0])
end
+ o.on '-si', '--singlethreaded', "Run Sidekiq in single thread mode which does all work synchronuously on the main thread." do |arg|
+ opts[:singlethreaded] = arg
+ end
+
o.on '-p', '--profile', "Profile all code run by Sidekiq" do |arg|
opts[:profile] = arg
end
View
12 lib/sidekiq/processor.rb
@@ -5,6 +5,8 @@
require 'sidekiq/middleware/server/retry_jobs'
require 'sidekiq/middleware/server/logging'
+require 'monitor'
+
module Sidekiq
##
# The Processor receives a message from the Manager and actually
@@ -45,7 +47,15 @@ def process(work)
stats(worker, msg, queue) do
Sidekiq.server_middleware.invoke(worker, msg, queue) do
- worker.perform(*cloned(msg['args']))
+ if $single_threaded
+ $monitor.synchronize do
+ $worker = worker
+ $worker_args = cloned(msg['args'])
+ $queue_wait_condition.signal
+ end
+ else
+ worker.perform(*cloned(msg['args']))
+ end
end
end
rescue Sidekiq::Shutdown
View
2 sidekiq.gemspec
@@ -9,7 +9,7 @@ Gem::Specification.new do |gem|
gem.license = "LGPL-3.0"
gem.executables = ['sidekiq', 'sidekiqctl']
- gem.files = `git ls-files | grep -Ev '^(myapp|examples)'`.split("\n")
+ gem.files = `git ls-files`.split("\n")
gem.test_files = `git ls-files -- test/*`.split("\n")
gem.name = "sidekiq"
gem.require_paths = ["lib"]

No commit comments for this range

Something went wrong with that request. Please try again.