sidekiq-priority 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README.md +44 -0
- data/Rakefile +12 -0
- data/lib/sidekiq/priority/server/fetch.rb +29 -0
- data/lib/sidekiq/priority/version.rb +5 -0
- data/lib/sidekiq/priority.rb +30 -0
- data/lib/sidekiq/superworker/subjob_processor.rb +22 -0
- data/lib/sidekiq/superworker/worker_class.rb +15 -0
- data/lib/sidekiq/worker_ext.rb +11 -0
- data/lib/sidekiq-priority.rb +1 -0
- metadata +71 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2013 SocialPandas
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
Sidekiq Priority
|
2
|
+
================
|
3
|
+
Prioritize Sidekiq jobs within queues
|
4
|
+
|
5
|
+
Overview
|
6
|
+
--------
|
7
|
+
|
8
|
+
Sidekiq Priority lets you prioritize the jobs within any Sidekiq queue.
|
9
|
+
|
10
|
+
For example, say you've added 5 jobs:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
5.times.do
|
14
|
+
MyWorker.perform_async(42)
|
15
|
+
end
|
16
|
+
```
|
17
|
+
|
18
|
+
Using Sidekiq Priority, you can add new jobs that have a higher priority by calling perform_with_priority instead of perform_async:
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
MyWorker.perform_with_priority(:high, 42)
|
22
|
+
```
|
23
|
+
|
24
|
+
This job won't interrupt any running jobs, but it'll start before any other jobs in the queue do.
|
25
|
+
|
26
|
+
You can also add jobs that should only run with lower priority than the default priority:
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
MyWorker.perform_with_priority(:low, 42)
|
30
|
+
```
|
31
|
+
|
32
|
+
### Custom Priorities
|
33
|
+
|
34
|
+
By default, two priorities are available: `:high` (above the default prioritization of perform_async) and `:low` (below the default prioritization), but you can add others (these values should be symbols, and `nil` represents the default prioritization):
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
# config/initializers/sidekiq_priority.rb
|
38
|
+
Sidekiq::Priorities.priorities = [:very_high, :high, nil, :low]
|
39
|
+
```
|
40
|
+
|
41
|
+
License
|
42
|
+
-------
|
43
|
+
|
44
|
+
Sidekiq Priority is released under the MIT License. Please see the MIT-LICENSE file for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'sidekiq/fetch'
|
2
|
+
|
3
|
+
module Sidekiq
|
4
|
+
module Priority
|
5
|
+
module Server
|
6
|
+
class Fetch < Sidekiq::BasicFetch
|
7
|
+
def initialize(options)
|
8
|
+
queues = prioritized_queues(options[:queues])
|
9
|
+
@strictly_ordered_queues = !!options[:strict]
|
10
|
+
@queues = queues.map { |q| "queue:#{q}" }
|
11
|
+
@unique_queues = @queues.uniq
|
12
|
+
end
|
13
|
+
|
14
|
+
protected
|
15
|
+
|
16
|
+
def prioritized_queues(base_queues)
|
17
|
+
queues = []
|
18
|
+
priorities = Sidekiq::Priority.priorities
|
19
|
+
priorities.each do |priority|
|
20
|
+
base_queues.each do |queue|
|
21
|
+
queues << Sidekiq::Priority.queue_with_priority(queue, priority)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
queues
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'sidekiq'
|
2
|
+
require 'celluloid'
|
3
|
+
|
4
|
+
directory = File.dirname(File.absolute_path(__FILE__))
|
5
|
+
Dir.glob("#{directory}/priority/**/*.rb") { |file| require file }
|
6
|
+
Dir.glob("#{directory}/superworker/**/*.rb") { |file| require file } if defined?(Sidekiq::Superworker)
|
7
|
+
require "#{directory}/worker_ext.rb"
|
8
|
+
|
9
|
+
module Sidekiq
|
10
|
+
module Priority
|
11
|
+
PRIORITIES = [:high, nil, :low]
|
12
|
+
|
13
|
+
def self.priorities
|
14
|
+
@priorities ||= PRIORITIES.dup
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.priorities=(priorities)
|
18
|
+
@priorities = priorities
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.queue_with_priority(queue, priority)
|
22
|
+
priority.nil? ? queue : "#{queue}_#{priority}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
Sidekiq.configure_server do |config|
|
28
|
+
Dir.glob("#{directory}/priority/server/*.rb") { |file| require file }
|
29
|
+
Sidekiq.options[:fetch] = Sidekiq::Priority::Server::Fetch
|
30
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Sidekiq
|
2
|
+
module Superworker
|
3
|
+
class SubjobProcessor
|
4
|
+
class << self
|
5
|
+
alias_method :original_sidekiq_item, :sidekiq_item
|
6
|
+
|
7
|
+
def sidekiq_item(subjob, klass, jid)
|
8
|
+
item = original_sidekiq_item(subjob, klass, jid)
|
9
|
+
|
10
|
+
# Modify the queue to be the prioritized queue, if necessary
|
11
|
+
priority = subjob.meta ? subjob.meta[:priority] : nil
|
12
|
+
if priority
|
13
|
+
queue = klass.get_sidekiq_options['queue']
|
14
|
+
queue = Sidekiq::Priority.queue_with_priority(queue, priority)
|
15
|
+
item['queue'] = queue
|
16
|
+
end
|
17
|
+
item
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Sidekiq
|
2
|
+
module Superworker
|
3
|
+
class WorkerClass
|
4
|
+
class << self
|
5
|
+
def perform_with_priority(priority, *arg_values)
|
6
|
+
options = initialize_superjob(arg_values)
|
7
|
+
options[:meta] ||= {}
|
8
|
+
options[:meta].merge!({ priority: priority })
|
9
|
+
subjobs = create_subjobs(arg_values, options)
|
10
|
+
SuperjobProcessor.create(@superjob_id, @class_name, arg_values, subjobs, options)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Sidekiq
|
2
|
+
module Worker
|
3
|
+
module ClassMethods
|
4
|
+
def perform_with_priority(priority, *args)
|
5
|
+
queue = self.get_sidekiq_options['queue']
|
6
|
+
queue = Sidekiq::Priority.queue_with_priority(queue, priority)
|
7
|
+
client_push('class' => self, 'args' => args, 'queue' => queue)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'sidekiq/priority'
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sidekiq-priority
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Tom Benner
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-09-10 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: sidekiq
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.1.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 2.1.0
|
30
|
+
description: Prioritize Sidekiq jobs within queues
|
31
|
+
email:
|
32
|
+
- tombenner@gmail.com
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- lib/sidekiq/priority/server/fetch.rb
|
38
|
+
- lib/sidekiq/priority/version.rb
|
39
|
+
- lib/sidekiq/priority.rb
|
40
|
+
- lib/sidekiq/superworker/subjob_processor.rb
|
41
|
+
- lib/sidekiq/superworker/worker_class.rb
|
42
|
+
- lib/sidekiq/worker_ext.rb
|
43
|
+
- lib/sidekiq-priority.rb
|
44
|
+
- MIT-LICENSE
|
45
|
+
- Rakefile
|
46
|
+
- README.md
|
47
|
+
homepage: https://github.com/socialpandas/sidekiq-priority
|
48
|
+
licenses: []
|
49
|
+
post_install_message:
|
50
|
+
rdoc_options: []
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ! '>='
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ! '>='
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
requirements: []
|
66
|
+
rubyforge_project:
|
67
|
+
rubygems_version: 1.8.24
|
68
|
+
signing_key:
|
69
|
+
specification_version: 3
|
70
|
+
summary: Prioritize Sidekiq jobs within queues
|
71
|
+
test_files: []
|