creeper 0.0.5 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -0
- data/LICENSE +1 -1
- data/README.md +16 -89
- data/Rakefile +0 -4
- data/creeper.gemspec +7 -8
- data/lib/creeper.rb +332 -224
- data/lib/creeper/celluloid_ext.rb +42 -0
- data/lib/creeper/creep.rb +10 -16
- data/lib/creeper/logger.rb +37 -0
- data/lib/creeper/version.rb +1 -1
- data/lib/creeper/worker.rb +260 -102
- metadata +43 -13
- data/lib/creeper/session.rb +0 -141
metadata
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: creeper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
|
-
-
|
8
|
+
- Lyon Hill
|
9
|
+
- Andrew Bennett
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
date: 2012-05-
|
13
|
+
date: 2012-05-29 00:00:00.000000000 Z
|
13
14
|
dependencies:
|
14
15
|
- !ruby/object:Gem::Dependency
|
15
16
|
name: pry
|
@@ -75,6 +76,38 @@ dependencies:
|
|
75
76
|
- - ! '>='
|
76
77
|
- !ruby/object:Gem::Version
|
77
78
|
version: '0'
|
79
|
+
- !ruby/object:Gem::Dependency
|
80
|
+
name: celluloid
|
81
|
+
requirement: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ! '>='
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
type: :runtime
|
88
|
+
prerelease: false
|
89
|
+
version_requirements: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ! '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: em-jack
|
97
|
+
requirement: !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
99
|
+
requirements:
|
100
|
+
- - ! '>='
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
type: :runtime
|
104
|
+
prerelease: false
|
105
|
+
version_requirements: !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
78
111
|
- !ruby/object:Gem::Dependency
|
79
112
|
name: kgio
|
80
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -91,9 +124,10 @@ dependencies:
|
|
91
124
|
- - ! '>='
|
92
125
|
- !ruby/object:Gem::Version
|
93
126
|
version: '0'
|
94
|
-
description:
|
127
|
+
description: Creeper is an evented version of Stalker
|
95
128
|
email:
|
96
129
|
- lyondhill@gmail.com
|
130
|
+
- potatosaladx@gmail.com
|
97
131
|
executables:
|
98
132
|
- creeper
|
99
133
|
extensions: []
|
@@ -109,16 +143,17 @@ files:
|
|
109
143
|
- creeper.gemspec
|
110
144
|
- examples/jack.rb
|
111
145
|
- lib/creeper.rb
|
146
|
+
- lib/creeper/celluloid_ext.rb
|
112
147
|
- lib/creeper/creep.rb
|
113
148
|
- lib/creeper/launcher.rb
|
114
|
-
- lib/creeper/
|
149
|
+
- lib/creeper/logger.rb
|
115
150
|
- lib/creeper/version.rb
|
116
151
|
- lib/creeper/worker.rb
|
117
152
|
- spec/lib/creeper/session_spec.rb
|
118
153
|
- spec/lib/creeper/worker_spec.rb
|
119
154
|
- spec/lib/creeper_spec.rb
|
120
155
|
- spec/spec_helper.rb
|
121
|
-
homepage: https://github.com/
|
156
|
+
homepage: https://github.com/potatosalad/creeper
|
122
157
|
licenses: []
|
123
158
|
post_install_message:
|
124
159
|
rdoc_options: []
|
@@ -130,27 +165,22 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
130
165
|
- - ! '>='
|
131
166
|
- !ruby/object:Gem::Version
|
132
167
|
version: '0'
|
133
|
-
segments:
|
134
|
-
- 0
|
135
|
-
hash: 1683539863185773873
|
136
168
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
137
169
|
none: false
|
138
170
|
requirements:
|
139
171
|
- - ! '>='
|
140
172
|
- !ruby/object:Gem::Version
|
141
173
|
version: '0'
|
142
|
-
segments:
|
143
|
-
- 0
|
144
|
-
hash: 1683539863185773873
|
145
174
|
requirements: []
|
146
175
|
rubyforge_project:
|
147
176
|
rubygems_version: 1.8.23
|
148
177
|
signing_key:
|
149
178
|
specification_version: 3
|
150
179
|
summary: A better solution for io bound jobs, same as stalker in functionality but
|
151
|
-
more
|
180
|
+
more evented
|
152
181
|
test_files:
|
153
182
|
- spec/lib/creeper/session_spec.rb
|
154
183
|
- spec/lib/creeper/worker_spec.rb
|
155
184
|
- spec/lib/creeper_spec.rb
|
156
185
|
- spec/spec_helper.rb
|
186
|
+
has_rdoc:
|
data/lib/creeper/session.rb
DELETED
@@ -1,141 +0,0 @@
|
|
1
|
-
module Creeper
|
2
|
-
class Session
|
3
|
-
|
4
|
-
attr_accessor :beanstalk, :beanstalk_url
|
5
|
-
attr_accessor :before_handlers, :error_handler, :handlers
|
6
|
-
|
7
|
-
def initialize(parent_session = nil)
|
8
|
-
if parent_session
|
9
|
-
@beanstalk_url = parent_session.beanstalk_url
|
10
|
-
@before_handlers = parent_session.before_handlers
|
11
|
-
@error_handler = parent_session.error_handler
|
12
|
-
@handlers = parent_session.handlers
|
13
|
-
end
|
14
|
-
|
15
|
-
@before_handlers ||= []
|
16
|
-
@handlers ||= {}
|
17
|
-
end
|
18
|
-
|
19
|
-
def clear!
|
20
|
-
handlers.clear
|
21
|
-
before_handlers.clear
|
22
|
-
self.error_handler = nil
|
23
|
-
end
|
24
|
-
|
25
|
-
## class methods ##
|
26
|
-
|
27
|
-
def self.beanstalk_addresses(beanstalk_url)
|
28
|
-
uris = beanstalk_url.split(/[\s,]+/)
|
29
|
-
uris.map do |uri|
|
30
|
-
beanstalk_host_and_port(uri)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def self.beanstalk_host_and_port(uri_string)
|
35
|
-
uri = URI.parse(uri_string)
|
36
|
-
raise(BadURL, uri_string) if uri.scheme != 'beanstalk'
|
37
|
-
"#{uri.host}:#{uri.port || 11300}"
|
38
|
-
end
|
39
|
-
|
40
|
-
def self.beanstalk_url
|
41
|
-
ENV['BEANSTALK_URL'] || 'beanstalk://localhost/'
|
42
|
-
end
|
43
|
-
|
44
|
-
##
|
45
|
-
|
46
|
-
## beanstalk ##
|
47
|
-
|
48
|
-
class BadURL < RuntimeError; end
|
49
|
-
|
50
|
-
def connect
|
51
|
-
Beanstalk::Pool.new(beanstalk_addresses)
|
52
|
-
end
|
53
|
-
|
54
|
-
def disconnect
|
55
|
-
beanstalk.close.tap do
|
56
|
-
@beanstalk = nil
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
def reconnect
|
61
|
-
disconnect rescue nil
|
62
|
-
beanstalk
|
63
|
-
end
|
64
|
-
|
65
|
-
def beanstalk
|
66
|
-
@beanstalk ||= connect
|
67
|
-
end
|
68
|
-
|
69
|
-
def beanstalk_url
|
70
|
-
@beanstalk_url ||= singleton_class.beanstalk_url
|
71
|
-
end
|
72
|
-
|
73
|
-
def beanstalk_addresses
|
74
|
-
singleton_class.beanstalk_addresses(beanstalk_url)
|
75
|
-
end
|
76
|
-
|
77
|
-
##
|
78
|
-
|
79
|
-
## handlers ##
|
80
|
-
|
81
|
-
def job(name, &block)
|
82
|
-
handlers[name] = block
|
83
|
-
end
|
84
|
-
|
85
|
-
def before(&block)
|
86
|
-
before_handlers << block
|
87
|
-
end
|
88
|
-
|
89
|
-
def error(&block)
|
90
|
-
self.error_handler = block
|
91
|
-
end
|
92
|
-
|
93
|
-
def all_jobs
|
94
|
-
handlers.keys
|
95
|
-
end
|
96
|
-
|
97
|
-
##
|
98
|
-
|
99
|
-
## queue ##
|
100
|
-
|
101
|
-
def enqueue(job, args = {}, opts = {})
|
102
|
-
pri = opts[:pri] || 65536
|
103
|
-
delay = [0, opts[:delay].to_i].max
|
104
|
-
ttr = opts[:ttr] || 120
|
105
|
-
beanstalk.use job
|
106
|
-
beanstalk.put [ job, args ].to_json, pri, delay, ttr
|
107
|
-
rescue Beanstalk::NotConnected => e
|
108
|
-
failed_connection(e)
|
109
|
-
end
|
110
|
-
|
111
|
-
##
|
112
|
-
|
113
|
-
protected
|
114
|
-
|
115
|
-
def failed_connection(e)
|
116
|
-
log_error exception_message(e)
|
117
|
-
log_error "*** Failed connection to #{beanstalk_url}"
|
118
|
-
log_error "*** Check that beanstalkd is running (or set a different BEANSTALK_URL)"
|
119
|
-
end
|
120
|
-
|
121
|
-
def log(msg)
|
122
|
-
Creeper.logger.info(msg)
|
123
|
-
end
|
124
|
-
|
125
|
-
def log_error(msg)
|
126
|
-
Creeper.error_logger.error(msg)
|
127
|
-
end
|
128
|
-
|
129
|
-
def exception_message(e)
|
130
|
-
msg = [ "Exception #{e.class} -> #{e.message}" ]
|
131
|
-
|
132
|
-
base = File.expand_path(Dir.pwd) + '/'
|
133
|
-
e.backtrace.each do |t|
|
134
|
-
msg << " #{File.expand_path(t).gsub(/#{base}/, '')}"
|
135
|
-
end
|
136
|
-
|
137
|
-
msg.join("\n")
|
138
|
-
end
|
139
|
-
|
140
|
-
end
|
141
|
-
end
|