simple_resque 1.0.1

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.
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm ruby-1.9.2-p180-patched@simple_resque --create
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source :rubygems
2
+ gemspec
3
+
4
+ group :test do
5
+ gem "rb-fsevent"
6
+ gem "growl"
7
+ gem "guard-spork"
8
+ gem "guard-rspec"
9
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,59 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ simple_resque (1.0.0)
5
+ resque
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ diff-lcs (1.1.3)
11
+ growl (1.0.3)
12
+ guard (0.5.1)
13
+ thor (~> 0.14.6)
14
+ guard-rspec (0.4.3)
15
+ guard (>= 0.4.0)
16
+ guard-spork (0.2.1)
17
+ guard (>= 0.2.2)
18
+ spork (>= 0.8.4)
19
+ multi_json (1.0.4)
20
+ rack (1.3.6)
21
+ rack-protection (1.2.0)
22
+ rack
23
+ rb-fsevent (0.4.0)
24
+ redis (2.2.2)
25
+ redis-namespace (1.0.3)
26
+ redis (< 3.0.0)
27
+ resque (1.19.0)
28
+ multi_json (~> 1.0)
29
+ redis-namespace (~> 1.0.2)
30
+ sinatra (>= 0.9.2)
31
+ vegas (~> 0.1.2)
32
+ rspec (2.7.0)
33
+ rspec-core (~> 2.7.0)
34
+ rspec-expectations (~> 2.7.0)
35
+ rspec-mocks (~> 2.7.0)
36
+ rspec-core (2.7.1)
37
+ rspec-expectations (2.7.0)
38
+ diff-lcs (~> 1.1.2)
39
+ rspec-mocks (2.7.0)
40
+ sinatra (1.3.2)
41
+ rack (~> 1.3, >= 1.3.6)
42
+ rack-protection (~> 1.2)
43
+ tilt (~> 1.3, >= 1.3.3)
44
+ spork (0.9.0.rc9)
45
+ thor (0.14.6)
46
+ tilt (1.3.3)
47
+ vegas (0.1.8)
48
+ rack (>= 1.0.0)
49
+
50
+ PLATFORMS
51
+ ruby
52
+
53
+ DEPENDENCIES
54
+ growl
55
+ guard-rspec
56
+ guard-spork
57
+ rb-fsevent
58
+ rspec
59
+ simple_resque!
data/Guardfile ADDED
@@ -0,0 +1,9 @@
1
+ guard 'spork', :cucumber => false, :test_unit => false, :rspec => true, :rspec_port => 10000 do
2
+ watch(%r{^spec/spec_helper.rb$})
3
+ end
4
+
5
+ guard 'rspec', all_on_start: true, cli: "--drb --color" do
6
+ watch(%r{spec/(.*)_spec.rb})
7
+ watch(%r{lib/(.*)\.rb}) { |m| "spec/lib/#{m[1]}_spec.rb" }
8
+ watch('spec/spec_helper.rb') { "spec" }
9
+ end
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Mike Subelsky
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,40 @@
1
+ # Simple Resque
2
+
3
+ I needed a simple way to queue Resque jobs from a web app where the jobs were defined in a separate "worker"
4
+ codebase, running completely independently from the web app. Unfortunately,
5
+ Resque requires you to pass the class name of a job as a constant, when what I
6
+ really needed was to pass a string which would get turned into a constant class
7
+ name by the worker codebase. The gem assumes that the queue name is an
8
+ underscored version of the class name.
9
+
10
+ I had to do this enough times that I decided to wrap the idiom in a gem, figuring that over time
11
+ I'll need to add other simplifications of the Resque API.
12
+
13
+ # Installation
14
+
15
+ gem install simple_resque
16
+
17
+ # Usage
18
+
19
+ require 'simple_resque'
20
+
21
+ # puts a job on the transmogrifier queue with class "Transmogrifier" and
22
+ # arguments { id: 3, state: "back_to_calvin" }
23
+
24
+ SimpleResque.push("Transmogrifier",id: 3, state: "back_to_calvin")
25
+
26
+ # Configuration
27
+
28
+ SimpleResque.resque = Resque
29
+ SimpleResque.resque = MyResqueMock # useful for unit testing
30
+
31
+ # Problems? Questions?
32
+
33
+ Email <mike@subelsky.com> or file an issue on
34
+ [GitHub](https://github.com/subelsky/simple_resque).
35
+
36
+ Patches are welcome. Thanks!
37
+
38
+ # License
39
+
40
+ See `MIT-LICENSE` for details.
data/Rakefile ADDED
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "rubygems"
4
+ require "bundler"
5
+
6
+ desc "release"
7
+ task :release do
8
+ unless system("git diff --exit-code")
9
+ puts "Git not clean. Aborting."
10
+ `growlnotify -m 'gem release failed'; say 'gem release failed'`
11
+ end
12
+
13
+ require "./lib/simple_resque/version.rb"
14
+
15
+ puts "Getting ready to tag and release #{SimpleResque::VERSION} - is this correct?"
16
+ answer = $stdin.gets.chomp!
17
+
18
+ exit if answer =~ /n/i
19
+
20
+ `bundle`
21
+ `git commit -ma "v#{SimpleResque::VERSION}"`
22
+ `git tag '#{SimpleResque::VERSION}'`
23
+ `gem build simple_resque.gemspec`
24
+ `gem push simple_resque-#{SimpleResque::VERSION}`
25
+ end
@@ -0,0 +1,60 @@
1
+ require "spec_helper"
2
+ require "subelsky_power_tools/environment"
3
+
4
+ describe SubelskyPowerTools::Environment do
5
+ context "extraction of required environment variables" do
6
+ def conduct_test(val1 = "shaz",val2 = "bot")
7
+ ENV['_SPT_EE_TEST_VALUE1'] = val1
8
+ ENV['_SPT_EE_TEST_VALUE2'] = val2
9
+ SubelskyPowerTools::Environment.extract!(:'_spt_ee_test_value1',:'_spt_ee_test_value2')
10
+ end
11
+
12
+ it "succeeds if all specified variables are non-blank" do
13
+ expect { conduct_test }.not_to raise_error
14
+ end
15
+
16
+ it "raises error if any specified variable is blank" do
17
+ expect { conduct_test(" ","bot") }.to raise_error(RuntimeError)
18
+ end
19
+
20
+ it "raises error if any specified variable is zero-width" do
21
+ expect { conduct_test("shaz","") }.to raise_error(RuntimeError)
22
+ end
23
+
24
+ it "raises error if any specified variable is nil" do
25
+ expect { conduct_test("",nil) }.to raise_error(RuntimeError)
26
+ end
27
+
28
+ it "returns the value of the extracted variables" do
29
+ val1, val2 = conduct_test("alpha","beta")
30
+ val1.should == "alpha"
31
+ val2.should == "beta"
32
+ end
33
+ end
34
+
35
+ context "extraction of optional environment variables" do
36
+ def conduct_test(val1 = "shaz",val2 = "bot")
37
+ ENV['_SPT_EE_TEST_VALUE1'] = val1
38
+ ENV['_SPT_EE_TEST_VALUE2'] = val2
39
+ SubelskyPowerTools::Environment.extract(:'_spt_ee_test_value1',:'_spt_ee_test_value2')
40
+ end
41
+
42
+ it "succeeds if any specified variable is blank" do
43
+ expect { conduct_test(" ","bot") }.not_to raise_error
44
+ end
45
+
46
+ it "succeeds if any specified variable is zero-width" do
47
+ expect { conduct_test("shaz","") }.not_to raise_error
48
+ end
49
+
50
+ it "suceeds if any specified variable is nil" do
51
+ expect { conduct_test("",nil) }.not_to raise_error
52
+ end
53
+
54
+ it "returns the value of the extracted variables" do
55
+ val1, val2 = conduct_test(nil,"beta")
56
+ val1.should == nil
57
+ val2.should == "beta"
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,3 @@
1
+ module SimpleResque
2
+ VERSION = "1.0.1"
3
+ end
@@ -0,0 +1,44 @@
1
+ module SimpleResque
2
+ extend self
3
+
4
+ def resque=(r)
5
+ @resque = r
6
+ end
7
+
8
+ def push(klass,args = nil)
9
+ queue_name = make_queue_name(klass)
10
+ resque.push(queue_name, class: klass, args: args)
11
+ end
12
+
13
+ def pop(klass)
14
+ queue_name = make_queue_name(klass)
15
+ resque.pop(queue_name)
16
+ end
17
+
18
+ def size(klass)
19
+ queue_name = make_queue_name(klass)
20
+ resque.size(queue_name)
21
+ end
22
+
23
+ def clear(klass)
24
+ queue_name = make_queue_name(klass)
25
+ resque.remove_queue(queue_name)
26
+ end
27
+
28
+ private
29
+
30
+ # this code borrowed from active_support's underscore method
31
+ def make_queue_name(klass)
32
+ name = klass.dup
33
+ name.gsub!(/::/, '/')
34
+ name.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
35
+ name.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
36
+ name.tr!("-", "_")
37
+ name.downcase!
38
+ name
39
+ end
40
+
41
+ def resque
42
+ @resque || Resque
43
+ end
44
+ end
@@ -0,0 +1,23 @@
1
+ $:.unshift(File.dirname(__FILE__))
2
+ require "lib/simple_resque/version"
3
+
4
+ desc = %q{Provides a simpler interface to enqueue Resque jobs between codebases without having to define the Jobs in multiple codebases.}
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{simple_resque}
8
+ s.version = SimpleResque::VERSION
9
+ s.authors = ["Mike Subelsky"]
10
+ s.date = Time.now.utc.strftime("%Y-%m-%d")
11
+ s.email = %q{mike@subelsky.com}
12
+ s.extra_rdoc_files = %w(README.md)
13
+ s.files = `git ls-files`.split("\n")
14
+ s.homepage = %q{http://github.com/subelsky/simple_resque}
15
+ s.rdoc_options = ["--charset=UTF-8"]
16
+ s.require_paths = ["lib"]
17
+ s.summary = desc
18
+ s.description = desc
19
+ s.test_files = `git ls-files spec`.split("\n")
20
+ s.add_dependency "resque"
21
+ s.add_development_dependency "rspec"
22
+ s.license = "MIT"
23
+ end
@@ -0,0 +1,40 @@
1
+ require "spec_helper"
2
+ require "simple_resque"
3
+
4
+ describe "Pushing a job to Resque" do
5
+ it "suceeds" do
6
+ expect {
7
+ SimpleResque.push("TransformVehicle",[5, "autobot"])
8
+ }.to change { Resque.size(:transform_vehicle) }.from(0).to(1)
9
+
10
+ job = Resque.pop(:transform_vehicle)
11
+ job["class"].should == "TransformVehicle"
12
+ job["args"].should == [5,"autobot"]
13
+ end
14
+ end
15
+
16
+ describe "Getting queue size from Resque" do
17
+ it "succeeds" do
18
+ SimpleResque.clear("BuyStuff")
19
+
20
+ expect {
21
+ SimpleResque.push("BuyStuff")
22
+ SimpleResque.push("BuyStuff")
23
+ }.to change { SimpleResque.size("BuyStuff") }.from(0).to(2)
24
+ end
25
+ end
26
+
27
+ describe "Popping jobs from Resque" do
28
+ it "succeeds" do
29
+ SimpleResque.clear("BuyStuff")
30
+ SimpleResque.push("Shaz",%q(1 2 3))
31
+ SimpleResque.pop("Shaz").should == { "class" => "Shaz", "args" => %q(1 2 3) }
32
+ end
33
+ end
34
+
35
+ describe "Clearing a Resque queue" do
36
+ it "succeeds" do
37
+ Resque.push(:buy_stuff,class: "BuyStuff", args: [])
38
+ expect { SimpleResque.clear("BuyStuff") }.to change { SimpleResque.size("BuyStuff") }.from(1).to(0)
39
+ end
40
+ end
@@ -0,0 +1,29 @@
1
+ require "spec_helper"
2
+ require "simple_resque"
3
+
4
+ describe SimpleResque do
5
+ let(:resque_stub) { stub("resque") }
6
+
7
+ before { SimpleResque.resque = resque_stub }
8
+
9
+ it "creates a proper push request from the given parameters" do
10
+ resque_stub.should_receive(:push).with("transmogrifier",class: "Transmogrifier",args: { id: 3, state: "back_to_calvin" })
11
+ SimpleResque.push("Transmogrifier",id: 3, state: "back_to_calvin")
12
+ end
13
+
14
+ it "returns the size of a given resque queue" do
15
+ resque_stub.should_receive(:size).with("count_score").and_return(3)
16
+ SimpleResque.size("CountScore").should == 3
17
+ end
18
+
19
+ it "pops the top off a given resque queue" do
20
+ data = { class: "GenerateFireball", args: [:a, :b] }
21
+ resque_stub.should_receive(:pop).with("generate_fireball").and_return(data)
22
+ SimpleResque.pop("GenerateFireball").should == data
23
+ end
24
+
25
+ it "clears the queue" do
26
+ resque_stub.should_receive(:remove_queue).with("howitzer")
27
+ SimpleResque.clear("Howitzer")
28
+ end
29
+ end
@@ -0,0 +1,44 @@
1
+ require "spork"
2
+ $:.unshift(File.join(File.dirname(__FILE__),"..","lib"))
3
+
4
+ Spork.prefork do
5
+ require "rspec"
6
+ require "redis"
7
+ require "resque"
8
+
9
+ redis_url = ENV["REDIS_URL"] || "http://localhost:6379"
10
+ redis_opts = URI.parse(redis_url)
11
+
12
+ redis_hash = {
13
+ host: redis_opts.host,
14
+ port: redis_opts.port,
15
+ password: redis_opts.password
16
+ }
17
+
18
+ Resque.redis = Redis.new(redis_hash)
19
+
20
+ RSpec.configure do |config|
21
+ config.mock_with :rspec
22
+
23
+ last_gc_run = Time.now
24
+
25
+ config.before(:each) do
26
+ GC.disable
27
+ end
28
+
29
+ config.after(:each) do
30
+ if Time.now - last_gc_run > 1.0
31
+ GC.enable
32
+ GC.start
33
+ last_gc_run = Time.now
34
+ end
35
+ end
36
+
37
+ end
38
+
39
+ require 'rspec/expectations'
40
+ require 'rspec/core/expecting/with_rspec'
41
+ end
42
+
43
+ Spork.each_run do
44
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simple_resque
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Mike Subelsky
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-21 00:00:00.000000000 -05:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: resque
17
+ requirement: &2153598600 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *2153598600
26
+ - !ruby/object:Gem::Dependency
27
+ name: rspec
28
+ requirement: &2153629400 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: *2153629400
37
+ description: Provides a simpler interface to enqueue Resque jobs between codebases
38
+ without having to define the Jobs in multiple codebases.
39
+ email: mike@subelsky.com
40
+ executables: []
41
+ extensions: []
42
+ extra_rdoc_files:
43
+ - README.md
44
+ files:
45
+ - .rvmrc
46
+ - Gemfile
47
+ - Gemfile.lock
48
+ - Guardfile
49
+ - MIT-LICENSE
50
+ - README.md
51
+ - Rakefile
52
+ - lib/environment_spec.rb
53
+ - lib/simple_resque.rb
54
+ - lib/simple_resque/version.rb
55
+ - simple_resque.gemspec
56
+ - spec/integration/resque_operations_spec.rb
57
+ - spec/lib/simple_resque_spec.rb
58
+ - spec/spec_helper.rb
59
+ has_rdoc: true
60
+ homepage: http://github.com/subelsky/simple_resque
61
+ licenses:
62
+ - MIT
63
+ post_install_message:
64
+ rdoc_options:
65
+ - --charset=UTF-8
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 1.6.2
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: Provides a simpler interface to enqueue Resque jobs between codebases without
86
+ having to define the Jobs in multiple codebases.
87
+ test_files:
88
+ - spec/integration/resque_operations_spec.rb
89
+ - spec/lib/simple_resque_spec.rb
90
+ - spec/spec_helper.rb