Skip to content
This repository was archived by the owner on Sep 22, 2022. It is now read-only.

Rename project #1

Merged
merged 1 commit into from
Jan 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
source "http://rubygems.org"
source 'http://rubygems.org'

# Specify your gem's dependencies in resque-unfairly.gemspec
# Specify your gem's dependencies in resque-roullete.gemspec
gemspec
15 changes: 5 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
![Status: Production](https://img.shields.io/badge/status-production-green.svg?style=flat)
![Open Source: yes](https://img.shields.io/badge/open_source-yes-green.svg?style=flat)
![Team: Research Tools](https://img.shields.io/badge/team-research_tools-green.svg?style=flat)

resque-unfairly
resque-roullete
===============

Usually Resque workers work on queues in the given order (if there is something in the first, work it, otherwise if the there is something in the second, work on it, and
Expand All @@ -14,13 +10,12 @@ project is inspired by [resque-fairly](https://github.com/pezra/resque-fairly) b

``` ruby
require 'resque'
require 'resque/plugins/unfairly'
require 'resque/plugins/roullete'

Resque::Plugins::Unfairly::prioritize("myqueue", 1)
Resque::Plugins::Unfairly::prioritize("myotherqueue", 3)
Resque::Plugins::Unfairly::prioritize("someotherqueue", 6)
Resque::Plugins::Roullete.prioritize('myqueue' 1)
Resque::Plugins::Roullete.prioritize('myotherqueue', 3)
Resque::Plugins::Roullete.prioritize('someotherqueue', 6)
```

Now, workers processing all three queues will (assuming all queues have jobs) take jobs from someotherqueue 60% of the time, myotherqueue 30% of the time, and myqueue 10% of the time. This is achieved
by reordering the queues, so if someotherqueue is empty, the workers will take jobs from myotherqueue 75% (3/4) of the time.

2 changes: 2 additions & 0 deletions lib/resque-roullete.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require 'resque'
require File.expand_path('resque/plugins/roullete', File.dirname(__FILE__))
3 changes: 0 additions & 3 deletions lib/resque-unfairly.rb

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
require 'resque/worker'

module Resque::Plugins
module Unfairly
module Roullete
# Define an 'unfair' priority multiplier to queues
def self.prioritize(queue, value)
priorities[queue] = value
end

def self.priorities
@priorities ||= {}
end

# Returns a list of queues to use when searching for a job. A
# splat ("*") means you want every queue
# splat ("*") means you want every queue
#
# The queues will be ordered randomly and the order will change
# with every call. This prevents any particular queue for being
Expand All @@ -22,7 +22,7 @@ def self.priorities
# If priorities have been established, the randomness of the order
# will be weighted according to the multipliers
def queues_randomly_ordered
queue_priorities = queues_orig_ordered.map{ |q| Unfairly.priorities[q] }
queue_priorities = queues_orig_ordered.map{ |q| Roullete.priorities[q] }
if queue_priorities.compact.any?
weighted_order(queues_orig_ordered, queue_priorities.map{|p| p or 1})
else
Expand All @@ -31,7 +31,7 @@ def queues_randomly_ordered
end

def self.included(klass)
klass.instance_eval do
klass.instance_eval do
alias_method :queues_orig_ordered, :queues
alias_method :queues, :queues_randomly_ordered
end
Expand Down Expand Up @@ -61,6 +61,6 @@ def weighted_order(vals, weights)
end
end

Resque::Worker.send(:include, Unfairly)
Resque::Worker.send(:include, Roullete)
end

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Resque
module Plugins
module Unfairly
VERSION = "0.0.1"
module Roullete
VERSION = '0.0.1'
end
end
end
Expand Down
25 changes: 11 additions & 14 deletions resque-unfairly.gemspec → resque-roullete.gemspec
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
# -*- encoding: utf-8 -*-
$:.push File.expand_path("../lib", __FILE__)
require "resque/plugins/unfairly/version"
$:.push File.expand_path('../lib', __FILE__)
require 'resque/plugins/roullete/version'

Gem::Specification.new do |s|
s.name = "resque-unfairly"
s.version = Resque::Plugins::Unfairly::VERSION
s.name = 'resque-roullete'
s.version = Resque::Plugins::Roullete::VERSION
s.platform = Gem::Platform::RUBY
s.authors = ["Evan Battaglia"]
s.email = ["evan@seomoz.org"]
s.homepage = ""
s.authors = ['Evan Battaglia', 'Bruno Casali']
s.email = ['evan@seomoz.org', 'bruno@trustvox.com.br']
s.homepage = ''
s.summary = %q{Order Resque queues probabilistically given a list of weights}
s.description = %q{Usually Resque workers work on queues in the given order (if there is something in the first, work it, otherwise if the there is something in the second, work on it, and so on). This plugin randomizes the order of the queues based on weights, so that a given queue will be the first queue to try based on a probability weight. Given queues A, B, C, D and weights 4, 3, 2, 1, repsectively, A will be first 40% of the time, B 30%, C 20%, and D 10%. In addition, when B is first, A will be second 4/7ths of the time (4 / [4+2+1]), and so on. The project is inspired by resque-fairly, which unfortunately mathematically does not give you this control over the weights.}

s.rubyforge_project = "resque-unfairly"

s.add_runtime_dependency "resque", "~>1.0"
s.add_development_dependency "rake", "~>0.8.7"
s.add_development_dependency "rspec", ">=1.3.0"
s.add_runtime_dependency 'resque', '~>1.0'
s.add_development_dependency 'rake', '~>0.8.7'
s.add_development_dependency 'rspec', '>=1.3.0'

s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]
s.require_paths = ['lib']
end
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require File.expand_path("../../spec_helper", File.dirname(__FILE__))
require File.expand_path('../../spec_helper', File.dirname(__FILE__))

describe Resque::Plugins::Unfairly do
describe Resque::Plugins::Roullete do
context 'with our own priorities' do
before do
described_class.instance_variable_set :@priorities, nil
Expand Down Expand Up @@ -36,7 +36,7 @@
counts['d'].should > 0.08 and counts['d'].should < 0.12
end
end

context "with weights 7, 1, 2, 0" do
let (:priorities) { { 'a' => 7, 'b' => 1, 'c' => 2, 'd' => 0 } }

Expand All @@ -49,8 +49,8 @@
end

end


context 'when priorities is not set' do
it 'consistenty gives the original order' do
10.times do
Expand Down
3 changes: 1 addition & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
require 'bundler'
Bundler.setup

require 'resque-unfairly'
require 'resque-roullete'
require 'rspec'
require 'rspec/autorun'

RSpec.configure do |config|
end