marcinbunsch-quick_queue 0.0.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.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Marcin Bunsch
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.rdoc ADDED
@@ -0,0 +1,14 @@
1
+ = quick_queue
2
+
3
+ quick_queue is a mix of Ruby's Queue and drb to produce an extremely simple to use queue system in pure Ruby.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Commit, do not mess with rakefile, version, or history.
10
+ * Send me a pull request. Bonus points for topic branches.
11
+
12
+ == Copyright
13
+
14
+ Copyright (c) 2009 Marcin Bunsch. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,56 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "quick_queue"
8
+ gem.summary = %Q{quick_queue is a mix of Ruby's Queue and drb to produce an extremely simple to use queue system in pure Ruby.}
9
+ #gem.description = %Q{TODO: longer description of your gem}
10
+ gem.email = "marcin@applicake.com"
11
+ gem.homepage = "http://github.com/marcinbunsch/quick_queue"
12
+ gem.authors = ["Marcin Bunsch"]
13
+ gem.files = FileList['*', '{bin,lib,images,spec}/**/*']
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ rescue LoadError
17
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
18
+ end
19
+
20
+ require 'rake/testtask'
21
+ Rake::TestTask.new(:test) do |test|
22
+ test.libs << 'lib' << 'test'
23
+ test.pattern = 'test/**/*_test.rb'
24
+ test.verbose = true
25
+ end
26
+
27
+ begin
28
+ require 'rcov/rcovtask'
29
+ Rcov::RcovTask.new do |test|
30
+ test.libs << 'test'
31
+ test.pattern = 'test/**/*_test.rb'
32
+ test.verbose = true
33
+ end
34
+ rescue LoadError
35
+ task :rcov do
36
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
37
+ end
38
+ end
39
+
40
+ task :test => :check_dependencies
41
+
42
+ task :default => :test
43
+
44
+ require 'rake/rdoctask'
45
+ Rake::RDocTask.new do |rdoc|
46
+ if File.exist?('VERSION')
47
+ version = File.read('VERSION')
48
+ else
49
+ version = ""
50
+ end
51
+
52
+ rdoc.rdoc_dir = 'rdoc'
53
+ rdoc.title = "quick_queue #{version}"
54
+ rdoc.rdoc_files.include('README*')
55
+ rdoc.rdoc_files.include('lib/**/*.rb')
56
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/bin/qq ADDED
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'quick_queue/server'
4
+ require 'optparse'
5
+
6
+ @options = {}
7
+ OptionParser.new do |opts|
8
+ opts.banner = "Usage: qs [options]"
9
+
10
+ opts.on("-p PORT", "--port PORT", "Specify port (default: 5000)") { |value| @options[:port] = value; }
11
+ opts.on("-f FILE", "--file FILE", "Specify file with data for queue (one item per line)") { |value| @options[:file] = value; }
12
+ opts.on("-q", "quit deamon (if present)") { }
13
+ opts.on("-d", "--deamon", "Run as a deamon process") { @options[:deamon] = true; }
14
+ opts.on_tail("-h", "--help", "Show this message") do
15
+ puts opts
16
+ exit
17
+ end
18
+ end.parse!
19
+
20
+ server = QuickQueue::Server.new(@options)
@@ -0,0 +1,45 @@
1
+ require 'drb'
2
+ module QuickQueue
3
+ class Client
4
+
5
+ def initialize(options = {})
6
+ port = (options[:port] || 7654)
7
+ DRb.start_service()
8
+ @server = DRbObject.new(nil, "druby://localhost:#{port}")
9
+ @current_item = nil
10
+ end
11
+
12
+ def fetch
13
+ @server.pop
14
+ end
15
+
16
+ def push(item)
17
+ @server.push(item)
18
+ end
19
+
20
+ def server_status
21
+ @server.status
22
+ end
23
+
24
+ def loop
25
+ begin
26
+ while item = fetch
27
+ @current_item = item
28
+ handle(item)
29
+ @current_item = nil
30
+ end
31
+ rescue
32
+ # if something went wrong, put it back in the queue
33
+ if @current_item
34
+ @server.push(@current_item)
35
+ @current_item = nil
36
+ end
37
+ end
38
+ end
39
+
40
+ def handle(item)
41
+ puts item
42
+ end
43
+
44
+ end
45
+ end
@@ -0,0 +1,55 @@
1
+ require 'drb'
2
+ module QuickQueue
3
+ class Server
4
+
5
+ def initialize(options = {})
6
+ start(options)
7
+ end
8
+
9
+ def pop
10
+ @size = 0 if @queue.size <= 1
11
+ return nil if @queue.empty?
12
+ @queue.pop
13
+ end
14
+
15
+ def push(item)
16
+ # currently it only supports strings
17
+ @queue.push item.to_s
18
+ @size += 1
19
+ end
20
+
21
+ def size
22
+ @size
23
+ end
24
+
25
+ def status
26
+ status = "Current queue status: "
27
+ if @size > 0
28
+ percentage = (((@queue.length.to_f / @size.to_f) * 10000.0).floor / 100.0)
29
+ status << "#{@queue.length} left of #{@size} (#{percentage}%)"
30
+ else
31
+ status << "queue is empty"
32
+ end
33
+ end
34
+
35
+ private
36
+
37
+ def start(options)
38
+ @queue = Queue.new
39
+ if options[:file] and File.exists?(options[:file])
40
+ lines = File.read(options[:file]).split("\n")
41
+ lines.each do |line|
42
+ @queue.push line
43
+ end
44
+ end
45
+ @size = @queue.length
46
+ trap('INT') { exit }
47
+ port = (options[:port] || 7654)
48
+ puts "quick_queue: server working at #{port}"
49
+ DRb.start_service("druby://localhost:#{port}", self)
50
+ DRb.thread.join
51
+ end
52
+
53
+ end
54
+ end
55
+
@@ -0,0 +1,4 @@
1
+ module QuickQueue
2
+ end
3
+ require 'quick_queue/server'
4
+ require 'quick_queue/client'
@@ -0,0 +1,52 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{quick_queue}
8
+ s.version = "0.0.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Marcin Bunsch"]
12
+ s.date = %q{2009-09-16}
13
+ s.default_executable = %q{qq}
14
+ s.email = %q{marcin@applicake.com}
15
+ s.executables = ["qq"]
16
+ s.extra_rdoc_files = [
17
+ "LICENSE",
18
+ "README.rdoc"
19
+ ]
20
+ s.files = [
21
+ "LICENSE",
22
+ "README.rdoc",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "bin/qq",
26
+ "lib/quick_queue.rb",
27
+ "lib/quick_queue/client.rb",
28
+ "lib/quick_queue/server.rb",
29
+ "quick_queue.gemspec",
30
+ "test_server.rb"
31
+ ]
32
+ s.has_rdoc = true
33
+ s.homepage = %q{http://github.com/marcinbunsch/quick_queue}
34
+ s.rdoc_options = ["--charset=UTF-8"]
35
+ s.require_paths = ["lib"]
36
+ s.rubygems_version = %q{1.3.1}
37
+ s.summary = %q{quick_queue is a mix of Ruby's Queue and drb to produce an extremely simple to use queue system in pure Ruby.}
38
+ s.test_files = [
39
+ "test/quick_queue_test.rb",
40
+ "test/test_helper.rb"
41
+ ]
42
+
43
+ if s.respond_to? :specification_version then
44
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
45
+ s.specification_version = 2
46
+
47
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
48
+ else
49
+ end
50
+ else
51
+ end
52
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class QuickQueueTest < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'quick_queue'
8
+
9
+ class Test::Unit::TestCase
10
+ end
data/test_server.rb ADDED
@@ -0,0 +1,3 @@
1
+ require 'rubygems'
2
+ require 'quick_queue/server'
3
+ QuickQueue::Server.new
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: marcinbunsch-quick_queue
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Marcin Bunsch
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-09-16 00:00:00 -07:00
13
+ default_executable: qq
14
+ dependencies: []
15
+
16
+ description:
17
+ email: marcin@applicake.com
18
+ executables:
19
+ - qq
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - LICENSE
24
+ - README.rdoc
25
+ files:
26
+ - LICENSE
27
+ - README.rdoc
28
+ - Rakefile
29
+ - VERSION
30
+ - bin/qq
31
+ - lib/quick_queue.rb
32
+ - lib/quick_queue/client.rb
33
+ - lib/quick_queue/server.rb
34
+ - quick_queue.gemspec
35
+ - test_server.rb
36
+ has_rdoc: true
37
+ homepage: http://github.com/marcinbunsch/quick_queue
38
+ licenses:
39
+ post_install_message:
40
+ rdoc_options:
41
+ - --charset=UTF-8
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: "0"
49
+ version:
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: "0"
55
+ version:
56
+ requirements: []
57
+
58
+ rubyforge_project:
59
+ rubygems_version: 1.3.5
60
+ signing_key:
61
+ specification_version: 2
62
+ summary: quick_queue is a mix of Ruby's Queue and drb to produce an extremely simple to use queue system in pure Ruby.
63
+ test_files:
64
+ - test/quick_queue_test.rb
65
+ - test/test_helper.rb