beanqueue 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gemtest +0 -0
- data/History.txt +4 -0
- data/Manifest.txt +5 -0
- data/README.rdoc +95 -0
- data/Rakefile +24 -0
- data/lib/beanqueue.rb +30 -0
- data/test/test_beanqueue.rb +52 -0
- metadata +98 -0
data/.gemtest
ADDED
File without changes
|
data/History.txt
ADDED
data/Manifest.txt
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
= beanqueue
|
2
|
+
|
3
|
+
* http://github.com/GearHead90/beanqueue
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
This is a beanstalk-based job-queueing-manager, replacement for gem 'stalker' with additions:
|
8
|
+
|
9
|
+
1. jobs grouping
|
10
|
+
2. jobs threading and forking
|
11
|
+
3. logging
|
12
|
+
4. background run (as daemon)
|
13
|
+
5. stalker makes to include full gem in application, but needed only client-side
|
14
|
+
|
15
|
+
This is a client-side gem. For a worker you need
|
16
|
+
|
17
|
+
* http://github.com/GearHead90/beanworker
|
18
|
+
|
19
|
+
== INSTALL:
|
20
|
+
|
21
|
+
gem install beanqueue
|
22
|
+
|
23
|
+
== CONFIGURATION:
|
24
|
+
|
25
|
+
in regular app:
|
26
|
+
|
27
|
+
require 'beanqueue'
|
28
|
+
Beanqueue.connect 'localhost:11300'
|
29
|
+
|
30
|
+
for multiple servers:
|
31
|
+
|
32
|
+
Beanqueue.connect 'localhost:11300', '192.168.1.1:11300', '192.168.1.1:11301'
|
33
|
+
|
34
|
+
in rails app just make config/beanstalk.yml:
|
35
|
+
|
36
|
+
host: localhost
|
37
|
+
port: 11300
|
38
|
+
|
39
|
+
or for multiple servers:
|
40
|
+
|
41
|
+
nodes:
|
42
|
+
- host: localhost
|
43
|
+
port: 11300
|
44
|
+
|
45
|
+
- host: 192.168.1.1
|
46
|
+
port: 11300
|
47
|
+
|
48
|
+
- host: 192.168.1.1
|
49
|
+
port: 11301
|
50
|
+
|
51
|
+
you can load YAML from non-Rails app with:
|
52
|
+
|
53
|
+
Beanqueue.load './config/beanstalk.yml'
|
54
|
+
|
55
|
+
== USAGE:
|
56
|
+
|
57
|
+
Beanqueue.push 'some.job', param1: 'val1', param2: 'val2'
|
58
|
+
|
59
|
+
or with params:
|
60
|
+
|
61
|
+
Beanqueue.push 'some.job',
|
62
|
+
{ param1: 'val1', param2: 'val2' },
|
63
|
+
timeout: 60.seconds, # job will be re-put after this time of execution
|
64
|
+
# default is 2.minutes
|
65
|
+
priority: 100, # beanstalk inner priority
|
66
|
+
# I prefer to use grouping instead
|
67
|
+
delay: 5, # delay job queuing
|
68
|
+
# default is 0
|
69
|
+
fork: true # does job should be performed in fork
|
70
|
+
# default is set in worker/job definition
|
71
|
+
|
72
|
+
== LICENSE:
|
73
|
+
|
74
|
+
(The MIT License)
|
75
|
+
|
76
|
+
Copyright (c) 2011 Andrew Shaydurov
|
77
|
+
|
78
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
79
|
+
a copy of this software and associated documentation files (the
|
80
|
+
'Software'), to deal in the Software without restriction, including
|
81
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
82
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
83
|
+
permit persons to whom the Software is furnished to do so, subject to
|
84
|
+
the following conditions:
|
85
|
+
|
86
|
+
The above copyright notice and this permission notice shall be
|
87
|
+
included in all copies or substantial portions of the Software.
|
88
|
+
|
89
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
90
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
91
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
92
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
93
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
94
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
95
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
gem 'hoe', '>= 2.1.0'
|
3
|
+
require 'hoe'
|
4
|
+
require 'fileutils'
|
5
|
+
require './lib/beanqueue'
|
6
|
+
|
7
|
+
Hoe.plugin :newgem
|
8
|
+
# Hoe.plugin :website
|
9
|
+
# Hoe.plugin :cucumberfeatures
|
10
|
+
|
11
|
+
# Generate all the Rake tasks
|
12
|
+
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
13
|
+
$hoe = Hoe.spec 'beanqueue' do
|
14
|
+
self.developer 'Andrew Shaydurov', 'gearhead@it-primorye.ru'
|
15
|
+
self.rubyforge_name = self.name
|
16
|
+
self.extra_deps = {'beanstalk-client' => '>=0'}
|
17
|
+
end
|
18
|
+
|
19
|
+
require 'newgem/tasks'
|
20
|
+
Dir['tasks/**/*.rake'].each { |t| load t }
|
21
|
+
|
22
|
+
# TODO - want other tests/tasks run by default? Add them to the list
|
23
|
+
# remove_task :default
|
24
|
+
# task :default => [:spec, :features]
|
data/lib/beanqueue.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'beanstalk-client'
|
2
|
+
|
3
|
+
module Beanqueue
|
4
|
+
VERSION = '0.0.1'
|
5
|
+
|
6
|
+
class << self
|
7
|
+
def load(yaml_path)
|
8
|
+
config = YAML.load(open(yaml_path))
|
9
|
+
if config['nodes']
|
10
|
+
connect *(config['nodes'].map { |node| "#{node['host']}:#{node['port']}" })
|
11
|
+
else
|
12
|
+
connect "#{config['host']}:#{config['port']}"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def connect(*nodes)
|
17
|
+
@connection = Beanstalk::Pool.new nodes.to_a
|
18
|
+
end
|
19
|
+
|
20
|
+
def push(name, args={}, opts={})
|
21
|
+
args['__fork__'] = opts[:fork] if opts[:fork]
|
22
|
+
@connection.use name
|
23
|
+
@connection.yput args, (opts[:priority] || 65536), [0, opts[:delay].to_i].max, (opts[:timeout] || 120)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
if defined? Rails
|
29
|
+
Beanqueue.load Rails.root.join('config', 'beanstalk.yml')
|
30
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require File.dirname(__FILE__) + '/../lib/beanqueue'
|
3
|
+
|
4
|
+
puts 'Be sure to set up beanstalk daemon on localhost:11300, also be sure to clean all queues'
|
5
|
+
|
6
|
+
class TestBeanqueue < Test::Unit::TestCase
|
7
|
+
|
8
|
+
def setup
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_connect
|
12
|
+
conn = Beanqueue.connect 'localhost:11300'
|
13
|
+
assert conn && conn.instance_eval { @connections['localhost:11300'] }, 'connection should be set up'
|
14
|
+
puts conn
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_load
|
18
|
+
conn = Beanqueue.load File.expand_path('../configs/one.yml', __FILE__)
|
19
|
+
assert conn && conn.instance_eval { @connections['localhost:11300'] }, 'connection from one-node YAML config should be set up'
|
20
|
+
|
21
|
+
conn = Beanqueue.load File.expand_path('../configs/many.yml', __FILE__)
|
22
|
+
assert conn && conn.instance_eval { @connections['localhost:11300'] }, 'connection from many-nodes YAML config should be set up'
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_push
|
26
|
+
conn_receiver = Beanstalk::Pool.new ['localhost:11300']
|
27
|
+
conn = Beanqueue.connect 'localhost:11300'
|
28
|
+
Beanqueue.push 'some.job'
|
29
|
+
|
30
|
+
conn_receiver.watch 'some.job'
|
31
|
+
|
32
|
+
job = nil
|
33
|
+
assert_nothing_raised do
|
34
|
+
job = conn_receiver.reserve(2)
|
35
|
+
end
|
36
|
+
job.delete
|
37
|
+
|
38
|
+
Beanqueue.push 'some.job', param1: 'val1', param2: 666, 'param3' => true
|
39
|
+
job = conn_receiver.reserve(2)
|
40
|
+
args = job.ybody
|
41
|
+
assert_equal({ param1: 'val1', param2: 666, 'param3' => true }, args, 'arguments are stored incorrectly')
|
42
|
+
job.delete
|
43
|
+
|
44
|
+
Beanqueue.push 'some.job', {}, fork: true, delay: 2, timeout: 300, priority: 100
|
45
|
+
job = conn_receiver.reserve(3)
|
46
|
+
assert_equal({ '__fork__' => true }, job.ybody, 'fork param is not stored')
|
47
|
+
assert_equal 2, job.delay, 'delay is not stored'
|
48
|
+
assert_equal 300, job.ttr, 'ttr is not stored'
|
49
|
+
assert_equal 100, job.pri, 'pri is not stored'
|
50
|
+
job.delete
|
51
|
+
end
|
52
|
+
end
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: beanqueue
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Andrew Shaydurov
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-10-19 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: beanstalk-client
|
16
|
+
requirement: &7981320 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *7981320
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: hoe
|
27
|
+
requirement: &7980780 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '2.12'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *7980780
|
36
|
+
description: ! 'This is a beanstalk-based job-queueing-manager, replacement for gem
|
37
|
+
''stalker'' with additions:
|
38
|
+
|
39
|
+
|
40
|
+
1. jobs grouping
|
41
|
+
|
42
|
+
2. jobs threading and forking
|
43
|
+
|
44
|
+
3. logging
|
45
|
+
|
46
|
+
4. background run (as daemon)
|
47
|
+
|
48
|
+
5. stalker makes to include full gem in application, but needed only client-side
|
49
|
+
|
50
|
+
|
51
|
+
This is a client-side gem. For a worker you need
|
52
|
+
|
53
|
+
|
54
|
+
* http://github.com/GearHead90/beanworker'
|
55
|
+
email:
|
56
|
+
- gearhead@it-primorye.ru
|
57
|
+
executables: []
|
58
|
+
extensions: []
|
59
|
+
extra_rdoc_files:
|
60
|
+
- History.txt
|
61
|
+
- Manifest.txt
|
62
|
+
files:
|
63
|
+
- History.txt
|
64
|
+
- Manifest.txt
|
65
|
+
- README.rdoc
|
66
|
+
- Rakefile
|
67
|
+
- lib/beanqueue.rb
|
68
|
+
- test/test_beanqueue.rb
|
69
|
+
- .gemtest
|
70
|
+
homepage: http://github.com/GearHead90/beanqueue
|
71
|
+
licenses: []
|
72
|
+
post_install_message:
|
73
|
+
rdoc_options:
|
74
|
+
- --main
|
75
|
+
- README.rdoc
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
80
|
+
requirements:
|
81
|
+
- - ! '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - ! '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
requirements: []
|
91
|
+
rubyforge_project: beanqueue
|
92
|
+
rubygems_version: 1.8.10
|
93
|
+
signing_key:
|
94
|
+
specification_version: 3
|
95
|
+
summary: ! 'This is a beanstalk-based job-queueing-manager, replacement for gem ''stalker''
|
96
|
+
with additions: 1'
|
97
|
+
test_files:
|
98
|
+
- test/test_beanqueue.rb
|