requeue 0.7.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b016469d47ba1bf79c6cf3e62421484e37ad5bb8
4
+ data.tar.gz: 520c9c9729a56fa27d36f3a47381cb39af834882
5
+ SHA512:
6
+ metadata.gz: ce9842d4de28ff5beb96a30c0e9f0b953f59647220af293a9425baa3fd79017f678c30ea7b583ea309d078e4e604204666dc5d904aa13c8194c4abf1e11ec5fa
7
+ data.tar.gz: 93578e2a7496f5a2b1d3c7ba268b14cfe0039203790d402dd38ef2bd7558bdc4d257838da61aff2b99db5654c0915e344acfe29b102fce6ca7beb6e0b9efdad5
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
@@ -0,0 +1 @@
1
+ 2.0.0-p353
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'redis'
4
+
5
+ group :development, :test do
6
+ gem 'fakeredis'
7
+ gem 'guard'
8
+ gem 'guard-rspec'
9
+ gem 'rspec'
10
+ gem "codeclimate-test-reporter", require: nil
11
+ end
12
+
13
+
@@ -0,0 +1,24 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard :rspec do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+
9
+ # Rails example
10
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
11
+ watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
12
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
13
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
14
+ watch('config/routes.rb') { "spec/routing" }
15
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
16
+
17
+ # Capybara features specs
18
+ watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
19
+
20
+ # Turnip features and steps
21
+ watch(%r{^spec/acceptance/(.+)\.feature$})
22
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
23
+ end
24
+
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Eric Fode
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # Requeue
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'requeue'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install requeue
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( https://github.com/[my-github-username]/requeue/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
Binary file
@@ -0,0 +1,66 @@
1
+ require 'redis'
2
+
3
+ module Requeue
4
+ class Queue
5
+ def initialize(redis: Redis.current, prefix: 'queue')
6
+ @prefix = prefix
7
+ @redis = redis
8
+ end
9
+
10
+ def name
11
+ "#{@prefix}:queue"
12
+ end
13
+
14
+ def list
15
+ @redis.lrange(name, 0, length)
16
+ end
17
+
18
+ def length
19
+ @redis.llen(name)
20
+ end
21
+
22
+ def clear!
23
+ @redis.del(name)
24
+ end
25
+
26
+ def enqueue!(value)
27
+ if (queued?(value) == false)
28
+ @redis.rpush(name, value)
29
+ else
30
+ length
31
+ end
32
+ end
33
+
34
+ def dequeue!
35
+ @redis.lpop(name)
36
+ end
37
+
38
+ def queued?(value)
39
+ list.include?(value)
40
+ end
41
+
42
+ def position(value)
43
+ list.index(value)
44
+ end
45
+
46
+ def remove!(value)
47
+ @redis.lrem(name,0,value)
48
+ end
49
+
50
+ def owner
51
+ @redis.lrange(name,0,1).first
52
+ end
53
+
54
+ def owned?
55
+ length > 0
56
+ end
57
+
58
+ def steal!(value)
59
+ @redis.lpush(name,value)
60
+ end
61
+
62
+ def as_json
63
+ {queue: list, owner: owner, length: length}.to_json
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,3 @@
1
+ module Requeue
2
+ VERSION = "0.7.0"
3
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'requeue/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "requeue"
8
+ spec.version = Requeue::VERSION
9
+ spec.authors = ["Eric Fode"]
10
+ spec.email = ["efode@lumoslabs.com"]
11
+ spec.summary = %q{A simple resque based queue}
12
+ spec.description = %q{A a very simple resque based queue}
13
+ spec.homepage = "https://www.github.com/lumoslabs/requeue"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
23
+ end
Binary file
@@ -0,0 +1,156 @@
1
+ require 'spec_helper'
2
+ describe Requeue::Queue do
3
+ before(:each) do
4
+ @redis = Redis.new
5
+ @queue = Requeue::Queue.new(prefix:'test', redis:@redis)
6
+ end
7
+
8
+ after(:each) do
9
+ @queue.clear!
10
+ end
11
+
12
+ describe '.queue_name' do
13
+ it { expect(@queue.name).to eq("test:queue") }
14
+ end
15
+
16
+ describe '.clear_queue!' do
17
+ before { @queue.enqueue!('eric') }
18
+ before { @queue.clear! }
19
+
20
+ it 'should empty the queue' do
21
+ expect(@redis.llen(@queue.name)).to eq(0)
22
+ end
23
+
24
+ it 'should see an empty queue' do
25
+ expect(@queue).not_to be_owned
26
+ end
27
+ end
28
+
29
+ describe '.enqueue' do
30
+ context 'when no users are enqueued' do
31
+ after { @queue.clear! }
32
+ it 'should return 1' do
33
+ expect(@queue.enqueue!('eric')).to eq(1)
34
+ end
35
+ end
36
+
37
+ context 'when some users are enqueued' do
38
+ before { @queue.enqueue!('bob') }
39
+ before { @queue.enqueue!('eric') }
40
+ after { @queue.clear! }
41
+ it 'should have a length of 2' do
42
+ expect(@queue.length).to eq(2)
43
+ end
44
+
45
+ it 'should only add the user to the queue if it is unique' do
46
+ expect(@queue.enqueue!('eric')).to eq(2)
47
+ expect(@queue.length).to eq(2)
48
+ end
49
+ end
50
+ end
51
+
52
+ describe '.list' do
53
+ context 'when no users are enqueued' do
54
+ it 'should return an empty list' do
55
+ expect(@queue.list).to eq([])
56
+ end
57
+ end
58
+
59
+ context 'when some users are enqueued' do
60
+ before { @queue.enqueue!('bob') }
61
+ before { @queue.enqueue!('eric') }
62
+ after { @queue.clear! }
63
+ it 'should have the current users' do
64
+ expect(@queue.list).to eq(['bob', 'eric'])
65
+ end
66
+ end
67
+ end
68
+ describe '.user_queued?' do
69
+ before { @queue.enqueue!('bob') }
70
+ before { @queue.enqueue!('eric') }
71
+ after { @queue.clear! }
72
+ it 'should show eric as queued' do
73
+ expect(@queue.queued? 'eric').to eq(true)
74
+ end
75
+ it 'should show bob as queued' do
76
+ expect(@queue.queued? 'bob').to eq(true)
77
+ end
78
+ it 'should not show an unqueued user as queued' do
79
+ expect(@queue.queued? 'jim').to eq(false)
80
+ end
81
+ end
82
+
83
+ describe '.user_position' do
84
+ before { @queue.enqueue!('bob') }
85
+ before { @queue.enqueue!('eric') }
86
+ after { @queue.clear! }
87
+ it 'eric should be in position 1 (the second place)' do
88
+ expect(@queue.position 'eric').to eq(1)
89
+ expect(@queue.position 'bob').to eq(0)
90
+ end
91
+ end
92
+
93
+ describe '.dequeue' do
94
+ before { @queue.enqueue!('bob') }
95
+ before { @queue.enqueue!('eric') }
96
+ before { @queue.dequeue! }
97
+ it 'eric should be in position 1 (the second place)' do
98
+ expect(@queue.position 'eric').to eq(0)
99
+ end
100
+ end
101
+
102
+ describe '.owner' do
103
+ context 'when no users are enqueued' do
104
+ it 'should return empty string' do
105
+ expect(@queue.owner).to eq(nil)
106
+ end
107
+ end
108
+
109
+ context 'when a user is enqueued' do
110
+ before { @queue.enqueue!('eric') }
111
+ it 'should be owned' do
112
+ expect(@queue.owner).to eq('eric')
113
+ end
114
+ end
115
+ end
116
+
117
+ describe '.remove!' do
118
+ before { @queue.enqueue!('bob') }
119
+ before { @queue.enqueue!('eric') }
120
+ before { @queue.remove!('eric') }
121
+
122
+ it 'should not contain eric anymore' do
123
+ expect(@queue.queued?('eric')).to eq(false)
124
+ expect(@queue.list).to eq(['bob'])
125
+ end
126
+ end
127
+
128
+ describe '.steal!' do
129
+ before { @queue.enqueue!('bob') }
130
+ before { @queue.enqueue!('eric') }
131
+ before { @queue.steal!('jim') }
132
+
133
+ it 'jim should own the queue' do
134
+ expect(@queue.owner()).to eq('jim')
135
+ expect(@queue.list).to eq(['jim','bob','eric'])
136
+ end
137
+
138
+ it 'the queue should still have everyone else in it' do
139
+ expect(@queue.length).to eq(3)
140
+ end
141
+ end
142
+ describe '.owned?' do
143
+ context 'when no users are enqueued' do
144
+ it 'should start unowned' do
145
+ expect(@queue).not_to be_owned
146
+ end
147
+ end
148
+
149
+ context 'when a user is enqueued' do
150
+ before { @queue.enqueue!('eric') }
151
+ it 'should be owned' do
152
+ expect(@queue).to be_owned
153
+ end
154
+ end
155
+ end
156
+ end
@@ -0,0 +1,24 @@
1
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
2
+ require 'codeclimate-test-reporter'
3
+ CodeClimate::TestReporter.start
4
+ require 'rspec/autorun'
5
+ require 'fakeredis/rspec'
6
+
7
+ RSpec.configure do |config|
8
+ # ## Mock Framework
9
+ #
10
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
11
+ #
12
+ # config.mock_with :mocha
13
+ # config.mock_with :flexmock
14
+ # config.mock_with :rr
15
+ #
16
+ # Run specs in random order to surface order dependencies. If you find an
17
+ # order dependency and want to debug it, you can fix the order by providing
18
+ # the seed, which is printed after each run.
19
+ # --seed 1234
20
+ config.order = "random"
21
+ end
22
+
23
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
24
+ require 'requeue'
@@ -0,0 +1,2 @@
1
+ require 'fakeredis/rspec'
2
+ $redis = Redis.new
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: requeue
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.7.0
5
+ platform: ruby
6
+ authors:
7
+ - Eric Fode
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: A a very simple resque based queue
42
+ email:
43
+ - efode@lumoslabs.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - .ruby-version
50
+ - Gemfile
51
+ - Guardfile
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - lib/.requeue.rb.swp
56
+ - lib/requeue.rb
57
+ - lib/requeue/version.rb
58
+ - requeue.gemspec
59
+ - spec/.requeue_spec.rb.swp
60
+ - spec/requeue_spec.rb
61
+ - spec/spec_helper.rb
62
+ - spec/support/fakeredis.rb
63
+ homepage: https://www.github.com/lumoslabs/requeue
64
+ licenses:
65
+ - MIT
66
+ metadata: {}
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 2.0.14
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: A simple resque based queue
87
+ test_files:
88
+ - spec/.requeue_spec.rb.swp
89
+ - spec/requeue_spec.rb
90
+ - spec/spec_helper.rb
91
+ - spec/support/fakeredis.rb