quebert 2.0.2 → 2.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rbenv-version +1 -1
- data/.travis.yml +9 -3
- data/Gemfile +1 -7
- data/lib/quebert.rb +4 -5
- data/lib/quebert/backend/beanstalk.rb +17 -8
- data/lib/quebert/controller/beanstalk.rb +3 -3
- data/lib/quebert/job.rb +2 -1
- data/lib/quebert/serializer.rb +2 -2
- data/lib/quebert/version.rb +1 -1
- data/spec/async_sender_spec.rb +2 -2
- data/spec/configuration_spec.rb +2 -2
- data/spec/consumer_spec.rb +2 -2
- data/spec/job_spec.rb +3 -3
- data/spec/serializer_spec.rb +1 -1
- data/spec/spec_helper.rb +6 -1
- data/spec/support/active_record.rb +2 -2
- metadata +28 -24
- data/lib/quebert/timeout.rb +0 -12
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 063bc22b230d2549c427562deb220554b1b6b931
|
4
|
+
data.tar.gz: 0f4db324c52f319abe1229112f0ea4219172f47d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b001d8710708db59714b9722c75cf0919ab1520a369ff2c3c246645450a02ba0e47235be186f805984d46693c7766b654bc579e73f8bca176c7176e37935e2ad
|
7
|
+
data.tar.gz: 76331a2a7b8600945285f562802b80f68954909d0b0a62f8b5ae857c8c5d782d5c364e74438f38ef542a91588ea2f2ba8dc7d46fa6abd107c59c07c46f4b5d28
|
data/.rbenv-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.9.3-
|
1
|
+
1.9.3-p484
|
data/.travis.yml
CHANGED
@@ -1,6 +1,12 @@
|
|
1
|
-
script: bundle exec rspec
|
2
1
|
language: ruby
|
3
2
|
rvm:
|
4
3
|
- 2.0.0
|
5
|
-
|
6
|
-
-
|
4
|
+
before_install:
|
5
|
+
- curl -L https://github.com/kr/beanstalkd/archive/v1.9.tar.gz | tar xz -C /tmp
|
6
|
+
- cd /tmp/beanstalkd-1.9/
|
7
|
+
- make
|
8
|
+
- ./beanstalkd &
|
9
|
+
- cd $TRAVIS_BUILD_DIR
|
10
|
+
script:
|
11
|
+
- bundle install
|
12
|
+
- bundle exec rspec
|
data/Gemfile
CHANGED
@@ -3,14 +3,8 @@ source "https://rubygems.org"
|
|
3
3
|
# Specify your gem's dependencies in quebert.gemspec
|
4
4
|
gemspec
|
5
5
|
|
6
|
-
group :development do
|
7
|
-
gem 'system_timer', :require => false, :platform => :ruby_18
|
8
|
-
end
|
9
|
-
|
10
6
|
group :test do
|
11
|
-
|
12
|
-
# gem 'ruby-debug19', :platform => :ruby_19
|
13
|
-
gem 'activerecord', '~> 2.3.0'
|
7
|
+
gem 'activerecord', '~> 4.0'
|
14
8
|
gem 'sqlite3-ruby'
|
15
9
|
gem 'guard-rspec'
|
16
10
|
gem 'rb-fsevent'
|
data/lib/quebert.rb
CHANGED
@@ -4,7 +4,6 @@ module Quebert
|
|
4
4
|
autoload :Logging, 'quebert/logging'
|
5
5
|
autoload :Serializer, 'quebert/serializer'
|
6
6
|
autoload :Configuration, 'quebert/configuration'
|
7
|
-
autoload :Timeout, 'quebert/timeout'
|
8
7
|
autoload :Job, 'quebert/job'
|
9
8
|
autoload :Controller, 'quebert/controller'
|
10
9
|
autoload :Backend, 'quebert/backend'
|
@@ -23,11 +22,11 @@ module Quebert
|
|
23
22
|
def backends
|
24
23
|
@backends ||= Support::Registry.new
|
25
24
|
end
|
26
|
-
|
25
|
+
|
27
26
|
def serializers
|
28
27
|
@serializers ||= Support::ClassRegistry.new
|
29
28
|
end
|
30
|
-
|
29
|
+
|
31
30
|
# Make this easier for elsewhere in the app
|
32
31
|
def logger
|
33
32
|
config.logger
|
@@ -39,9 +38,9 @@ module Quebert
|
|
39
38
|
block.call
|
40
39
|
end
|
41
40
|
end
|
42
|
-
|
41
|
+
|
43
42
|
# Register built-in Quebert backends
|
44
43
|
Quebert.backends.register :beanstalk, Backend::Beanstalk
|
45
44
|
Quebert.backends.register :in_process, Backend::InProcess
|
46
45
|
Quebert.backends.register :sync, Backend::Sync
|
47
|
-
end
|
46
|
+
end
|
@@ -5,17 +5,21 @@ module Quebert
|
|
5
5
|
|
6
6
|
# Manage jobs on a Beanstalk queue out of process
|
7
7
|
class Beanstalk
|
8
|
+
def initialize(host, tube_name)
|
9
|
+
@host, @tube_name = host, tube_name
|
10
|
+
end
|
11
|
+
|
8
12
|
def put(job, *args)
|
9
13
|
priority, delay, ttr = args
|
10
14
|
opts = {}
|
11
15
|
opts[:pri] = priority unless priority.nil?
|
12
16
|
opts[:delay] = delay unless delay.nil?
|
13
17
|
opts[:ttr] = ttr unless ttr.nil?
|
14
|
-
|
18
|
+
tube.put job.to_json, opts
|
15
19
|
end
|
16
20
|
|
17
21
|
def reserve_without_controller(timeout=nil)
|
18
|
-
|
22
|
+
tube.reserve timeout
|
19
23
|
end
|
20
24
|
|
21
25
|
def reserve(timeout=nil)
|
@@ -23,7 +27,7 @@ module Quebert
|
|
23
27
|
end
|
24
28
|
|
25
29
|
def peek(state)
|
26
|
-
|
30
|
+
tube.peek state
|
27
31
|
end
|
28
32
|
|
29
33
|
# For testing purposes... I think there's a better way to do this though.
|
@@ -35,19 +39,24 @@ module Quebert
|
|
35
39
|
reserve_without_controller.delete
|
36
40
|
end
|
37
41
|
while peek(:buried) do
|
38
|
-
|
42
|
+
tube.kick
|
39
43
|
reserve_without_controller.delete
|
40
44
|
end
|
41
45
|
end
|
42
46
|
|
43
|
-
def initialize(host, tube)
|
44
|
-
@pool = Beaneater::Pool.new Array(host)
|
45
|
-
@tube = @pool.tubes[tube]
|
46
|
-
end
|
47
47
|
def self.configure(opts={})
|
48
48
|
opts[:host] ||= ['127.0.0.1:11300']
|
49
49
|
new(opts[:host], opts[:tube])
|
50
50
|
end
|
51
|
+
|
52
|
+
private
|
53
|
+
def pool
|
54
|
+
@pool ||= Beaneater::Pool.new Array(@host)
|
55
|
+
end
|
56
|
+
|
57
|
+
def tube
|
58
|
+
@tube ||= pool.tubes[@tube_name]
|
59
|
+
end
|
51
60
|
end
|
52
61
|
end
|
53
62
|
end
|
@@ -68,7 +68,7 @@ module Quebert
|
|
68
68
|
log "Manually retrying with delay"
|
69
69
|
retry_with_delay
|
70
70
|
rescue Exception => e
|
71
|
-
log "Exception caught on perform.
|
71
|
+
log "Exception caught on perform. Burying job. #{e.inspect} #{e.backtrace.join("\n")}", :error
|
72
72
|
beanstalk_job.bury
|
73
73
|
log "Job buried", :error
|
74
74
|
raise e
|
@@ -89,7 +89,7 @@ module Quebert
|
|
89
89
|
beanstalk_job.release :pri => @job.priority, :delay => delay
|
90
90
|
log "Job released"
|
91
91
|
end
|
92
|
-
rescue ::Beaneater::NotFoundError
|
92
|
+
rescue ::Beaneater::NotFoundError
|
93
93
|
log "Job ran longer than allowed. Beanstalk already deleted it!!!!", :error
|
94
94
|
# Sometimes the timer doesn't behave correctly and this job actually runs longer than
|
95
95
|
# allowed. At that point the beanstalk job no longer exists anymore. Lets let it go and don't blow up.
|
@@ -102,4 +102,4 @@ module Quebert
|
|
102
102
|
end
|
103
103
|
end
|
104
104
|
end
|
105
|
-
end
|
105
|
+
end
|
data/lib/quebert/job.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'json'
|
2
|
+
require 'timeout'
|
2
3
|
|
3
4
|
module Quebert
|
4
5
|
class Job
|
@@ -53,7 +54,7 @@ module Quebert
|
|
53
54
|
# Honor the timeout and kill the job in ruby-space. Beanstalk
|
54
55
|
# should be cleaning up this job and returning it to the queue
|
55
56
|
# as well.
|
56
|
-
|
57
|
+
::Timeout.timeout(@ttr, Job::Timeout){ perform(*args) }
|
57
58
|
end
|
58
59
|
|
59
60
|
# Accepts arguments that override the job options and enqueu this stuff.
|
data/lib/quebert/serializer.rb
CHANGED
@@ -58,7 +58,7 @@ module Quebert
|
|
58
58
|
hash[attr] = val
|
59
59
|
hash
|
60
60
|
end
|
61
|
-
{ 'model' => record.class.model_name, 'attributes' => attrs }
|
61
|
+
{ 'model' => record.class.model_name.to_s, 'attributes' => attrs }
|
62
62
|
end
|
63
63
|
|
64
64
|
def self.deserialize(hash)
|
@@ -83,4 +83,4 @@ module Quebert
|
|
83
83
|
end
|
84
84
|
|
85
85
|
end
|
86
|
-
end
|
86
|
+
end
|
data/lib/quebert/version.rb
CHANGED
data/spec/async_sender_spec.rb
CHANGED
@@ -114,7 +114,7 @@ describe AsyncSender::ActiveRecord do
|
|
114
114
|
it "should async_send and successfully serialize param object" do
|
115
115
|
user = User.new(:first_name => 'Brad')
|
116
116
|
user2 = User.new(:first_name => 'Steel')
|
117
|
-
user.async.email(user2)
|
117
|
+
user.async.email!(user2)
|
118
118
|
@q.reserve.perform.first_name.should eql('Steel')
|
119
119
|
end
|
120
|
-
end
|
120
|
+
end
|
data/spec/configuration_spec.rb
CHANGED
@@ -10,9 +10,9 @@ describe Configuration do
|
|
10
10
|
backend = @config.backend
|
11
11
|
backend.should be_instance_of(Quebert::Backend::Beanstalk)
|
12
12
|
# Blech, gross nastiness in their lib, but we need to look in to see if this stuff as configed
|
13
|
-
pool = backend.
|
13
|
+
pool = backend.send(:pool)
|
14
14
|
pool.connections.first.address.should eql('localhost:11300')
|
15
|
-
tube = backend.
|
15
|
+
tube = backend.send(:tube)
|
16
16
|
tube.name.should eql('quebert-config-test')
|
17
17
|
end
|
18
18
|
|
data/spec/consumer_spec.rb
CHANGED
@@ -89,11 +89,11 @@ describe Controller::Beanstalk do
|
|
89
89
|
sleep(3)
|
90
90
|
|
91
91
|
# lets set the max retry delay so it should bury instead of delay
|
92
|
-
Quebert::Controller::Beanstalk
|
92
|
+
redefine_constant Quebert::Controller::Beanstalk, :MAX_TIMEOUT_RETRY_DELAY, 1
|
93
93
|
lambda{@q.reserve.perform}.should raise_exception(Quebert::Job::Timeout)
|
94
94
|
|
95
95
|
@q.peek(:ready).should be_nil
|
96
96
|
@q.peek(:delayed).should be_nil
|
97
97
|
@q.peek(:buried).should_not be_nil
|
98
98
|
end
|
99
|
-
end
|
99
|
+
end
|
data/spec/job_spec.rb
CHANGED
@@ -109,7 +109,7 @@ describe Quebert::Job do
|
|
109
109
|
describe "async promise DSL" do
|
110
110
|
it "should enqueue and honor beanstalk options" do
|
111
111
|
user = User.new(:first_name => "Steel")
|
112
|
-
user.async(:priority => 1, :delay => 2, :ttr => 300).email("somebody", nil, nil)
|
112
|
+
user.async(:priority => 1, :delay => 2, :ttr => 300).email!("somebody", nil, nil)
|
113
113
|
job = @q.reserve
|
114
114
|
job.beanstalk_job.pri.should eql(1)
|
115
115
|
job.beanstalk_job.delay.should eql(2)
|
@@ -128,7 +128,7 @@ describe Quebert::Job do
|
|
128
128
|
describe "legacy async_send" do
|
129
129
|
it "should enqueue and honor beanstalk options" do
|
130
130
|
user = User.new(:first_name => "Steel")
|
131
|
-
user.async_send(:email
|
131
|
+
user.async_send(:email!, "somebody", nil, nil, :beanstalk => {:priority => 1, :delay => 2, :ttr => 300})
|
132
132
|
job = @q.reserve
|
133
133
|
job.beanstalk_job.pri.should eql(1)
|
134
134
|
job.beanstalk_job.delay.should eql(2)
|
@@ -153,4 +153,4 @@ describe Quebert::Job do
|
|
153
153
|
}.should raise_exception(Quebert::Job::Timeout)
|
154
154
|
end
|
155
155
|
end
|
156
|
-
end
|
156
|
+
end
|
data/spec/serializer_spec.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -22,6 +22,11 @@ def clean_file(path, contents=nil, &block)
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
+
def redefine_constant(obj, const, value)
|
26
|
+
obj.send(:remove_const, const) if obj.const_defined?(const)
|
27
|
+
obj.const_set(const, value)
|
28
|
+
end
|
29
|
+
|
25
30
|
Dir[File.join(File.dirname(__FILE__), 'support/*.rb')].each {|file| require file }
|
26
31
|
|
27
|
-
Quebert.serializers.register 'ActiveRecord::Base', Serializer::ActiveRecord
|
32
|
+
Quebert.serializers.register 'ActiveRecord::Base', Serializer::ActiveRecord
|
metadata
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: quebert
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
5
|
-
prerelease:
|
4
|
+
version: 2.0.3
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Brad Gessler
|
@@ -11,42 +10,50 @@ authors:
|
|
11
10
|
autorequire:
|
12
11
|
bindir: bin
|
13
12
|
cert_chain: []
|
14
|
-
date:
|
15
|
-
default_executable:
|
13
|
+
date: 2014-07-18 00:00:00.000000000 Z
|
16
14
|
dependencies:
|
17
15
|
- !ruby/object:Gem::Dependency
|
18
16
|
name: json
|
19
|
-
requirement:
|
20
|
-
none: false
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
21
18
|
requirements:
|
22
|
-
- -
|
19
|
+
- - '>='
|
23
20
|
- !ruby/object:Gem::Version
|
24
21
|
version: '0'
|
25
22
|
type: :runtime
|
26
23
|
prerelease: false
|
27
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - '>='
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: '0'
|
28
29
|
- !ruby/object:Gem::Dependency
|
29
30
|
name: beaneater
|
30
|
-
requirement:
|
31
|
-
none: false
|
31
|
+
requirement: !ruby/object:Gem::Requirement
|
32
32
|
requirements:
|
33
|
-
- -
|
33
|
+
- - '>='
|
34
34
|
- !ruby/object:Gem::Version
|
35
35
|
version: '0'
|
36
36
|
type: :runtime
|
37
37
|
prerelease: false
|
38
|
-
version_requirements:
|
38
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - '>='
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
39
43
|
- !ruby/object:Gem::Dependency
|
40
44
|
name: rspec
|
41
|
-
requirement:
|
42
|
-
none: false
|
45
|
+
requirement: !ruby/object:Gem::Requirement
|
43
46
|
requirements:
|
44
|
-
- - =
|
47
|
+
- - '='
|
45
48
|
- !ruby/object:Gem::Version
|
46
49
|
version: 2.7.0
|
47
50
|
type: :development
|
48
51
|
prerelease: false
|
49
|
-
version_requirements:
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - '='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 2.7.0
|
50
57
|
description: A worker queue framework built around beanstalkd
|
51
58
|
email:
|
52
59
|
- brad@bradgessler.com
|
@@ -89,7 +96,6 @@ files:
|
|
89
96
|
- lib/quebert/support.rb
|
90
97
|
- lib/quebert/support/pid_file.rb
|
91
98
|
- lib/quebert/support/registry.rb
|
92
|
-
- lib/quebert/timeout.rb
|
93
99
|
- lib/quebert/version.rb
|
94
100
|
- lib/quebert/worker.rb
|
95
101
|
- quebert.gemspec
|
@@ -106,30 +112,28 @@ files:
|
|
106
112
|
- spec/support/jobs.rb
|
107
113
|
- spec/support_spec.rb
|
108
114
|
- spec/worker_spec.rb
|
109
|
-
has_rdoc: true
|
110
115
|
homepage: http://github.com/polleverywhere/quebert
|
111
116
|
licenses: []
|
117
|
+
metadata: {}
|
112
118
|
post_install_message:
|
113
119
|
rdoc_options: []
|
114
120
|
require_paths:
|
115
121
|
- lib
|
116
122
|
required_ruby_version: !ruby/object:Gem::Requirement
|
117
|
-
none: false
|
118
123
|
requirements:
|
119
|
-
- -
|
124
|
+
- - '>='
|
120
125
|
- !ruby/object:Gem::Version
|
121
126
|
version: '0'
|
122
127
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
|
-
none: false
|
124
128
|
requirements:
|
125
|
-
- -
|
129
|
+
- - '>='
|
126
130
|
- !ruby/object:Gem::Version
|
127
131
|
version: '0'
|
128
132
|
requirements: []
|
129
133
|
rubyforge_project: quebert
|
130
|
-
rubygems_version:
|
134
|
+
rubygems_version: 2.2.0
|
131
135
|
signing_key:
|
132
|
-
specification_version:
|
136
|
+
specification_version: 4
|
133
137
|
summary: A worker queue framework built around beanstalkd
|
134
138
|
test_files:
|
135
139
|
- spec/async_sender_spec.rb
|
data/lib/quebert/timeout.rb
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
# Setup a namespaced Quebert::Timeout class that will deal with responsible folks in
|
2
|
-
# 1.8.7 who use the SystemTimer gem.
|
3
|
-
module Quebert
|
4
|
-
Timeout = begin
|
5
|
-
require 'system_timer'
|
6
|
-
::SystemTimer
|
7
|
-
rescue LoadError
|
8
|
-
# Install the system_timer gem if you're running this in Ruby 1.8.7!
|
9
|
-
require 'timeout'
|
10
|
-
::Timeout
|
11
|
-
end
|
12
|
-
end
|