quick_queue 0.1.2

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.
@@ -0,0 +1,37 @@
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
+ === installation
6
+
7
+ Simple:
8
+
9
+ sudo gem install marcinbunsch-quick_queue
10
+
11
+ === usage
12
+
13
+ Simpler:
14
+
15
+ To use the server, type *qq* in the console. That's it.
16
+
17
+ To use the client, either use or extend the QuickQueue::Client class:
18
+
19
+ require 'quick_queue/client'
20
+ client = QuickQueue::Client.new
21
+ client.server_status
22
+ => "Current queue status: queue is empty"
23
+ client.push 'item'
24
+ => 1
25
+ client.fetch
26
+ => 'item'
27
+
28
+ == Note on Patches/Pull Requests
29
+
30
+ * Fork the project.
31
+ * Make your feature addition or bug fix.
32
+ * Commit, do not mess with rakefile, version, or history.
33
+ * Send me a pull request. Bonus points for topic branches.
34
+
35
+ == Copyright
36
+
37
+ Copyright (c) 2009 Marcin Bunsch. See LICENSE for details.
@@ -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.2
data/bin/qq ADDED
@@ -0,0 +1,21 @@
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("-h HOST", "--host HOST", "Specify host (default: localhost)") { |value| @options[:host] = value; }
12
+ opts.on("-f FILE", "--file FILE", "Specify file with data for queue (one item per line)") { |value| @options[:file] = value; }
13
+ opts.on("-q", "quit deamon (if present)") { }
14
+ opts.on("-d", "--deamon", "Run as a deamon process") { @options[:deamon] = true; }
15
+ opts.on_tail("-h", "--help", "Show this message") do
16
+ puts opts
17
+ exit
18
+ end
19
+ end.parse!
20
+
21
+ server = QuickQueue::Server.new(@options)
data/bin/qqc ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'quick_queue/console'
4
+ require 'optparse'
5
+
6
+ @options = {}
7
+ OptionParser.new do |opts|
8
+ opts.banner = "Usage: qqc [options]"
9
+ opts.on("-p PORT", "--port PORT", "Specify port (default: 5000)") { |value| @options[:port] = value; }
10
+ opts.on("-h HOST", "--host HOST", "Specify host (default: localhost)") { |value| @options[:host] = value; }
11
+ opts.on_tail("-h", "--help", "Show this message") do
12
+ puts opts
13
+ exit
14
+ end
15
+ end.parse!
16
+
17
+ QuickQueue::Console.new(@options).loop
@@ -0,0 +1,4 @@
1
+ module QuickQueue
2
+ end
3
+ require 'quick_queue/server'
4
+ require 'quick_queue/client'
@@ -0,0 +1,51 @@
1
+ require 'drb'
2
+ module QuickQueue
3
+ class Client
4
+
5
+ def initialize(options = {})
6
+ port = (options[:port] || 7654)
7
+ host = (options[:host] || 'localhost')
8
+ @worker = File.read(options[:file]) if options[:file]
9
+ DRb.start_service()
10
+ @server = DRbObject.new(nil, "druby://#{host}:#{port}")
11
+ @current_item = nil
12
+ end
13
+
14
+ def fetch
15
+ @server.pop
16
+ end
17
+ alias :pop :fetch
18
+
19
+ def push(item)
20
+ @server.push(item)
21
+ end
22
+
23
+ def server_status
24
+ @server.status
25
+ end
26
+ alias :status :server_status
27
+
28
+ def loop
29
+ while item = fetch
30
+ begin
31
+ @current_item = item
32
+ handle(item)
33
+ @current_item = nil
34
+ rescue
35
+ # if something went wrong, put it back in the queue
36
+ if @current_item
37
+ @logger.info("Failed to process #{@current_item}, putting it back in queue") if @logger
38
+ @logger.info("Reason for failure: #{$!.class}: #{$!.message} at #{$!.backtrace.first}") if @logger
39
+ @server.push(@current_item)
40
+ @current_item = nil
41
+ end
42
+ end
43
+ end
44
+ end
45
+
46
+ def handle(item)
47
+ puts item
48
+ end
49
+
50
+ end
51
+ end
@@ -0,0 +1,20 @@
1
+ require 'quick_queue/client'
2
+ require "readline"
3
+ module QuickQueue
4
+ class Console < Client
5
+ include Readline
6
+ def loop
7
+ while (command = readline('> ', true)).chomp != 'exit'
8
+ next if command == ''
9
+ method, *args = command.split(' ')
10
+ if ['status', 'server_status', 'fetch', 'push', 'pop'].include?(method)
11
+ eval "puts(#{method} #{args.join(' ')})" rescue $stdout.puts($!.message)
12
+ else
13
+ puts "No such command - #{method}"
14
+ end
15
+ end
16
+ puts 'Bye'
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,56 @@
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
+ host = (options[:host] || 'localhost')
49
+ puts "quick_queue: server working at #{host}:#{port}"
50
+ DRb.start_service("druby://#{host}:#{port}", self)
51
+ DRb.thread.join
52
+ end
53
+
54
+ end
55
+ end
56
+
@@ -0,0 +1,53 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{quick_queue}
8
+ s.version = "0.1.2"
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-11-06}
13
+ s.email = %q{marcin@applicake.com}
14
+ s.executables = ["qq", "qqc"]
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ "LICENSE",
21
+ "README.rdoc",
22
+ "Rakefile",
23
+ "VERSION",
24
+ "bin/qq",
25
+ "bin/qqc",
26
+ "lib/quick_queue.rb",
27
+ "lib/quick_queue/client.rb",
28
+ "lib/quick_queue/console.rb",
29
+ "lib/quick_queue/server.rb",
30
+ "quick_queue.gemspec",
31
+ "test_server.rb"
32
+ ]
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.5}
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 = 3
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
53
+
@@ -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
@@ -0,0 +1,3 @@
1
+ require 'rubygems'
2
+ require 'quick_queue/server'
3
+ QuickQueue::Server.new
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: quick_queue
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Marcin Bunsch
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-11-25 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: marcin@applicake.com
18
+ executables:
19
+ - qq
20
+ - qqc
21
+ extensions: []
22
+
23
+ extra_rdoc_files:
24
+ - LICENSE
25
+ - README.rdoc
26
+ files:
27
+ - LICENSE
28
+ - README.rdoc
29
+ - Rakefile
30
+ - VERSION
31
+ - bin/qq
32
+ - bin/qqc
33
+ - lib/quick_queue.rb
34
+ - lib/quick_queue/client.rb
35
+ - lib/quick_queue/console.rb
36
+ - lib/quick_queue/server.rb
37
+ - quick_queue.gemspec
38
+ - test_server.rb
39
+ has_rdoc: true
40
+ homepage: http://github.com/marcinbunsch/quick_queue
41
+ licenses: []
42
+
43
+ post_install_message:
44
+ rdoc_options:
45
+ - --charset=UTF-8
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: "0"
53
+ version:
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: "0"
59
+ version:
60
+ requirements: []
61
+
62
+ rubyforge_project:
63
+ rubygems_version: 1.3.5
64
+ signing_key:
65
+ specification_version: 3
66
+ summary: quick_queue is a mix of Ruby's Queue and drb to produce an extremely simple to use queue system in pure Ruby.
67
+ test_files:
68
+ - test/quick_queue_test.rb
69
+ - test/test_helper.rb