enqueue 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (9) hide show
  1. data/Gemfile +3 -0
  2. data/Gemfile.lock +67 -0
  3. data/LICENSE +20 -0
  4. data/README.md +213 -0
  5. data/Rakefile +61 -0
  6. data/VERSION +1 -0
  7. data/enqueue.gemspec +54 -0
  8. data/lib/enqueue.rb +5 -0
  9. metadata +200 -0
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source :rubygems
2
+
3
+ gemspec
@@ -0,0 +1,67 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ enqueue (0.0.1)
5
+ version (~> 1.0)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ at (0.1.4)
11
+ version (~> 1.0)
12
+ coderay (1.0.8)
13
+ diff-lcs (1.1.3)
14
+ fuubar (1.1.0)
15
+ rspec (~> 2.0)
16
+ rspec-instafail (~> 0.2.0)
17
+ ruby-progressbar (~> 1.0.0)
18
+ github-markup (0.7.4)
19
+ guard (1.5.4)
20
+ listen (>= 0.4.2)
21
+ lumberjack (>= 1.0.2)
22
+ pry (>= 0.9.10)
23
+ thor (>= 0.14.6)
24
+ guard-rspec (2.3.1)
25
+ guard (>= 1.1)
26
+ rspec (~> 2.11)
27
+ guard-yard (2.0.1)
28
+ guard (>= 1.1.0)
29
+ yard (>= 0.7.0)
30
+ listen (0.6.0)
31
+ lumberjack (1.0.2)
32
+ method_source (0.8.1)
33
+ pry (0.9.10)
34
+ coderay (~> 1.0.5)
35
+ method_source (~> 0.8)
36
+ slop (~> 3.3.1)
37
+ rake (10.0.3)
38
+ rb-fsevent (0.9.2)
39
+ redcarpet (2.2.2)
40
+ rspec (2.12.0)
41
+ rspec-core (~> 2.12.0)
42
+ rspec-expectations (~> 2.12.0)
43
+ rspec-mocks (~> 2.12.0)
44
+ rspec-core (2.12.1)
45
+ rspec-expectations (2.12.0)
46
+ diff-lcs (~> 1.1.3)
47
+ rspec-instafail (0.2.4)
48
+ rspec-mocks (2.12.0)
49
+ ruby-progressbar (1.0.2)
50
+ slop (3.3.3)
51
+ thor (0.16.0)
52
+ version (1.0.0)
53
+ yard (0.8.3)
54
+
55
+ PLATFORMS
56
+ ruby
57
+
58
+ DEPENDENCIES
59
+ at (~> 0.1)
60
+ enqueue!
61
+ fuubar (~> 1.1)
62
+ github-markup (~> 0.7)
63
+ guard-rspec (~> 2.1)
64
+ guard-yard (~> 2.0)
65
+ rake (~> 10.0)
66
+ rb-fsevent (~> 0.9)
67
+ redcarpet (~> 2.2.2)
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Ryan Scott Lewis <ryan@rynet.us>.
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,213 @@
1
+ # Enqueue
2
+
3
+ __enqueue__ _verb_ _\en′kyü\_ __:__ To add an item to a queue.
4
+
5
+ Enqueue is an interface to [message queues][message_queue] for easy parallel processing and
6
+ multi-threading.
7
+
8
+ ## Install
9
+
10
+ ### Bundler: `gem 'enqueue'`
11
+
12
+ ### RubyGems: `gem install enqueue`
13
+
14
+ ## Usage
15
+
16
+ ### Publisher
17
+
18
+ A publisher is any object that can find and push messages to a queue.
19
+
20
+ #### Defining
21
+
22
+ You can define a publisher by subclassing `Enqueue::Publisher` or by including/extending
23
+ `Enqueue::Publisher::Base`.
24
+
25
+ #### Global Methods
26
+
27
+ Besides the methods that are mixed into publisher by an adapter, all publishers
28
+ will have the following methods:
29
+
30
+ #### Class
31
+
32
+ `adapter(name)`
33
+ *returns: true, false*
34
+
35
+ **name** <Symbol, #to_sym> The name of the adapter to mixin.
36
+
37
+ Remove any previous adapter specific methods and include the module associated with the given Symbol.
38
+
39
+ > Note: Adapters *will* overwrite any instance/class method that it uses.
40
+ > Not all adapters have the same set of methods so you may have to investigate which methods
41
+ > not to use when integrating the ability to publish to a queue onto an existing object.
42
+
43
+ #### Instance
44
+
45
+ `enqueue(message, options={})`
46
+ *aliases: push, shift, <<*
47
+ *returns: Enqueue::Message*
48
+
49
+ **message** \<Object> The message to push. Note that some adapters require this to be a String.
50
+ **options** <Hash, #to_hash, #to_h> The adapter-specific options.
51
+
52
+ Push a message to the/a queue.
53
+
54
+ ### Subscriber
55
+
56
+ A subscriber is any object that can find and pop messages off a queue.
57
+
58
+ #### Defining
59
+
60
+ Just like a publisher, you can define a subscriber by subclassing `Enqueue::Subscriber` or by
61
+ including/extending `Enqueue::Subscriber::Base`.
62
+
63
+ #### Global Methods
64
+
65
+ Besides the methods that are mixed into publisher by an adapter, all publishers
66
+ will have the following methods:
67
+
68
+ #### Class
69
+
70
+ `adapter(name)`
71
+ *returns: true, false*
72
+
73
+ **name** <Symbol, #to_sym> The name of the adapter to mixin.
74
+
75
+ Remove any previous adapter specific methods and include the module associated with the given Symbol.
76
+
77
+ #### Instance
78
+
79
+ `pop(options={})`
80
+ *aliases: dequeue, unshift*
81
+ *returns: Enqueue::Message*
82
+
83
+ **options** <Hash, #to_hash, #to_h> The adapter-specific options.
84
+
85
+ Push a message to the/a queue.
86
+
87
+ `run`
88
+
89
+ In a loop, wait until the queue has a message. When it does, pop it off.
90
+
91
+ > Note: All adapters overwrite this method.
92
+
93
+ `run!`
94
+ *returns: Thread*
95
+
96
+ Call `run` in a new thread.
97
+
98
+ ### Example
99
+
100
+ #### Ruby Queue
101
+
102
+ By default, Enqueue uses the [Queue][queue] class from the Ruby standard library.
103
+
104
+ `my_pub_sub`
105
+
106
+ ```ruby
107
+ #!/usr/bin/env ruby
108
+
109
+ subscribers, publishers, threads = [], [], []
110
+
111
+ trap('INT') do
112
+ print 'Killing all publishers... '
113
+ publishers.each(&:disconnect)
114
+ puts 'Done!'
115
+
116
+ print 'Killing all subscribers... '
117
+ subscribers.each(&:disconnect)
118
+ puts 'Done!'
119
+ end
120
+ puts "Press CTRL-C to exit."
121
+
122
+ 5.times do
123
+ publisher = Enqueue::Publisher.new
124
+ publishers << publisher
125
+ threads << Thread.new do
126
+ loop do
127
+ sleep rand(10)
128
+ publisher.push 'Hello, World!'
129
+ end
130
+ end
131
+ end
132
+
133
+ 5.times do
134
+ subscriber = Enqueue::Subscriber.new
135
+ subscribers << subscriber
136
+ threads << subscriber.run!
137
+ end
138
+ ```
139
+
140
+ #### RabbitMQ
141
+
142
+ `my_pub_sub`
143
+
144
+ ```ruby
145
+ #!/usr/bin/env ruby
146
+
147
+ class Publisher < Enqueue::Publisher
148
+ adapter :rabbit_mq
149
+ # This class now has RabbitMQ specific class and
150
+ # instance methods:
151
+ host 'localhost'
152
+ port 5672
153
+
154
+ def notify(message)
155
+ enqueue message, to: 'my_message_queue'
156
+ end
157
+ end
158
+
159
+ class Subscriber < Enqueue::Subscriber
160
+ adapter :rabbit_mq
161
+ # This class now has RabbitMQ specific class and
162
+ # instance methods:
163
+ host 'localhost'
164
+ port 5672
165
+
166
+ subscribe :print_message, to: 'my_message_queue'
167
+
168
+ def print_message(message)
169
+ puts message
170
+ end
171
+ end
172
+
173
+ subscribers, publishers, threads = [], [], []
174
+
175
+ trap('INT') do
176
+ print 'Disconnecting all publishers... '
177
+ publishers.each(&:disconnect)
178
+ puts 'Done!'
179
+
180
+ print 'Disconnecting all subscribers... '
181
+ subscribers.each(&:disconnect)
182
+ puts 'Done!'
183
+ end
184
+ puts "Press CTRL-C to exit."
185
+
186
+ 5.times do
187
+ publisher = Publisher.new
188
+ publishers << publisher
189
+ publisher.connect
190
+ threads << Thread.new do
191
+ loop do
192
+ sleep rand(10)
193
+ publisher.notify 'Hello, World!'
194
+ end
195
+ end
196
+ end
197
+
198
+ 5.times do
199
+ subscriber = Subscriber.new
200
+ subscribers << subscriber
201
+ subscriber.connect
202
+ threads << subscriber.run!
203
+ end
204
+ ```
205
+
206
+ ## Copyright
207
+
208
+ Copyright © 2012 Ryan Scott Lewis <ryan@rynet.us>.
209
+
210
+ The MIT License (MIT) - See LICENSE for further details.
211
+
212
+ [message_queue]: http://en.wikipedia.org/wiki/Message_queue
213
+ [queue]: http://rubydoc.info/stdlib/thread/Queue
@@ -0,0 +1,61 @@
1
+ require 'pathname'
2
+
3
+ def require_task(path)
4
+ begin
5
+ require path
6
+
7
+ yield
8
+ rescue LoadError
9
+ puts '', "Could not load '#{path}'.", 'Try to `rake gem:spec` and `bundle install` and try again.', ''
10
+ end
11
+ end
12
+
13
+ spec = Gem::Specification.new do |s|
14
+
15
+ # Variables
16
+ s.name = 'enqueue'
17
+ s.author = 'Ryan Scott Lewis'
18
+ s.email = 'ryan@rynet.us'
19
+ s.summary = 'Enqueue is an interface to message queues for easy parallel processing.'
20
+ s.description = 'Interface with message queues with ease.'
21
+ s.post_install_message = 'Enqueue is not yet finished, check back with this gem has a MINOR version!'
22
+
23
+ # Dependencies
24
+ s.add_dependency 'version', '~> 1.0'
25
+ s.add_development_dependency 'at', '~> 0.1'
26
+ s.add_development_dependency 'rake', '~> 10.0'
27
+ s.add_development_dependency 'guard-rspec', '~> 2.1'
28
+ s.add_development_dependency 'guard-yard', '~> 2.0'
29
+ s.add_development_dependency 'rb-fsevent', '~> 0.9'
30
+ s.add_development_dependency 'fuubar', '~> 1.1'
31
+ s.add_development_dependency 'redcarpet', '~> 2.2.2'
32
+ s.add_development_dependency 'github-markup', '~> 0.7'
33
+
34
+ # Pragmatically set variables
35
+ s.homepage = "http://github.com/RyanScottLewis/#{s.name}"
36
+ s.version = Pathname.glob('VERSION*').first.read
37
+ s.require_paths = ['lib']
38
+ s.files = `git ls-files`.lines.to_a.collect { |s| s.strip }
39
+ s.executables = `git ls-files -- bin/*`.lines.to_a.collect { |s| File.basename(s.strip) }
40
+
41
+ end
42
+
43
+ desc 'Generate the gemspec defined in this Rakefile'
44
+ task :gemspec do
45
+ Pathname.new("#{spec.name}.gemspec").open('w') { |f| f.write(spec.to_ruby) }
46
+ end
47
+
48
+ require_task 'rake/version_task' do
49
+ Rake::VersionTask.new do |t|
50
+ t.with_git_tag = true
51
+ t.with_gemspec = spec
52
+ end
53
+ end
54
+
55
+ require 'rubygems/package_task'
56
+ Gem::PackageTask.new(spec) do |t|
57
+ t.need_zip = false
58
+ t.need_tar = false
59
+ end
60
+
61
+ task :default => :gemspec
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,54 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "enqueue"
5
+ s.version = "0.0.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Ryan Scott Lewis"]
9
+ s.date = "2012-12-13"
10
+ s.description = "Interface with message queues with ease."
11
+ s.email = "ryan@rynet.us"
12
+ s.files = ["Gemfile", "Gemfile.lock", "LICENSE", "README.md", "Rakefile", "VERSION", "enqueue.gemspec", "lib/enqueue.rb"]
13
+ s.homepage = "http://github.com/RyanScottLewis/enqueue"
14
+ s.post_install_message = "Enqueue is not yet finished, check back with this gem has a MINOR version!"
15
+ s.require_paths = ["lib"]
16
+ s.rubygems_version = "1.8.24"
17
+ s.summary = "Enqueue is an interface to message queues for easy parallel processing."
18
+
19
+ if s.respond_to? :specification_version then
20
+ s.specification_version = 3
21
+
22
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
23
+ s.add_runtime_dependency(%q<version>, ["~> 1.0"])
24
+ s.add_development_dependency(%q<at>, ["~> 0.1"])
25
+ s.add_development_dependency(%q<rake>, ["~> 10.0"])
26
+ s.add_development_dependency(%q<guard-rspec>, ["~> 2.1"])
27
+ s.add_development_dependency(%q<guard-yard>, ["~> 2.0"])
28
+ s.add_development_dependency(%q<rb-fsevent>, ["~> 0.9"])
29
+ s.add_development_dependency(%q<fuubar>, ["~> 1.1"])
30
+ s.add_development_dependency(%q<redcarpet>, ["~> 2.2.2"])
31
+ s.add_development_dependency(%q<github-markup>, ["~> 0.7"])
32
+ else
33
+ s.add_dependency(%q<version>, ["~> 1.0"])
34
+ s.add_dependency(%q<at>, ["~> 0.1"])
35
+ s.add_dependency(%q<rake>, ["~> 10.0"])
36
+ s.add_dependency(%q<guard-rspec>, ["~> 2.1"])
37
+ s.add_dependency(%q<guard-yard>, ["~> 2.0"])
38
+ s.add_dependency(%q<rb-fsevent>, ["~> 0.9"])
39
+ s.add_dependency(%q<fuubar>, ["~> 1.1"])
40
+ s.add_dependency(%q<redcarpet>, ["~> 2.2.2"])
41
+ s.add_dependency(%q<github-markup>, ["~> 0.7"])
42
+ end
43
+ else
44
+ s.add_dependency(%q<version>, ["~> 1.0"])
45
+ s.add_dependency(%q<at>, ["~> 0.1"])
46
+ s.add_dependency(%q<rake>, ["~> 10.0"])
47
+ s.add_dependency(%q<guard-rspec>, ["~> 2.1"])
48
+ s.add_dependency(%q<guard-yard>, ["~> 2.0"])
49
+ s.add_dependency(%q<rb-fsevent>, ["~> 0.9"])
50
+ s.add_dependency(%q<fuubar>, ["~> 1.1"])
51
+ s.add_dependency(%q<redcarpet>, ["~> 2.2.2"])
52
+ s.add_dependency(%q<github-markup>, ["~> 0.7"])
53
+ end
54
+ end
@@ -0,0 +1,5 @@
1
+ require 'version'
2
+
3
+ module Enqueue
4
+ is_versioned
5
+ end
metadata ADDED
@@ -0,0 +1,200 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: enqueue
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ryan Scott Lewis
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-13 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: version
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: at
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '0.1'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '0.1'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '10.0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: guard-rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '2.1'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '2.1'
78
+ - !ruby/object:Gem::Dependency
79
+ name: guard-yard
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: '2.0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: '2.0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: rb-fsevent
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: '0.9'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: '0.9'
110
+ - !ruby/object:Gem::Dependency
111
+ name: fuubar
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: '1.1'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ~>
124
+ - !ruby/object:Gem::Version
125
+ version: '1.1'
126
+ - !ruby/object:Gem::Dependency
127
+ name: redcarpet
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ~>
132
+ - !ruby/object:Gem::Version
133
+ version: 2.2.2
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ~>
140
+ - !ruby/object:Gem::Version
141
+ version: 2.2.2
142
+ - !ruby/object:Gem::Dependency
143
+ name: github-markup
144
+ requirement: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ~>
148
+ - !ruby/object:Gem::Version
149
+ version: '0.7'
150
+ type: :development
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ~>
156
+ - !ruby/object:Gem::Version
157
+ version: '0.7'
158
+ description: Interface with message queues with ease.
159
+ email: ryan@rynet.us
160
+ executables: []
161
+ extensions: []
162
+ extra_rdoc_files: []
163
+ files:
164
+ - Gemfile
165
+ - Gemfile.lock
166
+ - LICENSE
167
+ - README.md
168
+ - Rakefile
169
+ - VERSION
170
+ - enqueue.gemspec
171
+ - lib/enqueue.rb
172
+ homepage: http://github.com/RyanScottLewis/enqueue
173
+ licenses: []
174
+ post_install_message: Enqueue is not yet finished, check back with this gem has a
175
+ MINOR version!
176
+ rdoc_options: []
177
+ require_paths:
178
+ - lib
179
+ required_ruby_version: !ruby/object:Gem::Requirement
180
+ none: false
181
+ requirements:
182
+ - - ! '>='
183
+ - !ruby/object:Gem::Version
184
+ version: '0'
185
+ segments:
186
+ - 0
187
+ hash: -4127432239887490786
188
+ required_rubygems_version: !ruby/object:Gem::Requirement
189
+ none: false
190
+ requirements:
191
+ - - ! '>='
192
+ - !ruby/object:Gem::Version
193
+ version: '0'
194
+ requirements: []
195
+ rubyforge_project:
196
+ rubygems_version: 1.8.24
197
+ signing_key:
198
+ specification_version: 3
199
+ summary: Enqueue is an interface to message queues for easy parallel processing.
200
+ test_files: []