tribe 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +21 -0
- data/Gemfile +3 -14
- data/Gemfile.lock +9 -63
- data/{LICENSE.txt → LICENSE} +3 -1
- data/README.md +29 -0
- data/Rakefile +71 -99
- data/lib/tribe/actor.rb +53 -35
- data/lib/tribe/dedicated_actor.rb +9 -0
- data/lib/tribe/mailbox.rb +15 -28
- data/lib/tribe/registry.rb +23 -22
- data/lib/tribe/version.rb +3 -0
- data/lib/tribe.rb +10 -21
- data/tribe.gemspec +14 -88
- metadata +25 -183
- data/.document +0 -5
- data/.rspec +0 -1
- data/Guardfile +0 -9
- data/README.rdoc +0 -19
- data/VERSION +0 -1
- data/lib/tribe/dispatcher.rb +0 -16
- data/lib/tribe/message.rb +0 -15
- data/lib/tribe/scheduler.rb +0 -78
- data/lib/tribe/thread_pool.rb +0 -58
- data/lib/tribe/timer.rb +0 -51
- data/lib/tribe/worker.rb +0 -28
- data/spec/lib/tribe/actor_spec.rb +0 -15
- data/spec/lib/tribe/dispatcher_spec.rb +0 -4
- data/spec/lib/tribe/registry_spec.rb +0 -4
- data/spec/lib/tribe/scheduler_spec.rb +0 -4
- data/spec/lib/tribe/timer_spec.rb +0 -4
- data/spec/lib/tribe/worker_spec.rb +0 -4
- data/spec/spec_helper.rb +0 -16
data/tribe.gemspec
CHANGED
@@ -1,93 +1,19 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
1
|
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/tribe/version', __FILE__)
|
5
3
|
|
6
|
-
Gem::Specification.new do |
|
7
|
-
|
8
|
-
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Chad Remesch"]
|
6
|
+
gem.email = ["chad@remesch.com"]
|
7
|
+
gem.description = %q{Event driven actors for Ruby}
|
8
|
+
gem.summary = %q{Event driven actors for Ruby designed for high performance.}
|
9
|
+
gem.homepage = ""
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
"LICENSE.txt",
|
17
|
-
"README.rdoc"
|
18
|
-
]
|
19
|
-
s.files = [
|
20
|
-
".document",
|
21
|
-
".rspec",
|
22
|
-
"Gemfile",
|
23
|
-
"Gemfile.lock",
|
24
|
-
"Guardfile",
|
25
|
-
"LICENSE.txt",
|
26
|
-
"README.rdoc",
|
27
|
-
"Rakefile",
|
28
|
-
"VERSION",
|
29
|
-
"lib/tribe.rb",
|
30
|
-
"lib/tribe/actor.rb",
|
31
|
-
"lib/tribe/dispatcher.rb",
|
32
|
-
"lib/tribe/mailbox.rb",
|
33
|
-
"lib/tribe/message.rb",
|
34
|
-
"lib/tribe/registry.rb",
|
35
|
-
"lib/tribe/scheduler.rb",
|
36
|
-
"lib/tribe/thread_pool.rb",
|
37
|
-
"lib/tribe/timer.rb",
|
38
|
-
"lib/tribe/worker.rb",
|
39
|
-
"spec/lib/tribe/actor_spec.rb",
|
40
|
-
"spec/lib/tribe/dispatcher_spec.rb",
|
41
|
-
"spec/lib/tribe/registry_spec.rb",
|
42
|
-
"spec/lib/tribe/scheduler_spec.rb",
|
43
|
-
"spec/lib/tribe/timer_spec.rb",
|
44
|
-
"spec/lib/tribe/worker_spec.rb",
|
45
|
-
"spec/spec_helper.rb",
|
46
|
-
"tribe.gemspec"
|
47
|
-
]
|
48
|
-
s.homepage = "http://github.com/chadrem/tribe"
|
49
|
-
s.licenses = ["MIT"]
|
50
|
-
s.require_paths = ["lib"]
|
51
|
-
s.rubygems_version = "1.8.23"
|
52
|
-
s.summary = "Actor Model for Ruby"
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "tribe"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Tribe::VERSION
|
53
17
|
|
54
|
-
|
55
|
-
s.specification_version = 3
|
56
|
-
|
57
|
-
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
58
|
-
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
59
|
-
s.add_development_dependency(%q<rspec>, ["~> 2.10.0"])
|
60
|
-
s.add_development_dependency(%q<bundler>, [">= 1.1.0"])
|
61
|
-
s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
|
62
|
-
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
63
|
-
s.add_development_dependency(%q<rb-fsevent>, [">= 0"])
|
64
|
-
s.add_development_dependency(%q<guard>, ["~> 1.1.1"])
|
65
|
-
s.add_development_dependency(%q<guard-rspec>, ["~> 1.0.0"])
|
66
|
-
s.add_development_dependency(%q<growl>, [">= 0"])
|
67
|
-
s.add_development_dependency(%q<debugger>, [">= 0"])
|
68
|
-
else
|
69
|
-
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
70
|
-
s.add_dependency(%q<rspec>, ["~> 2.10.0"])
|
71
|
-
s.add_dependency(%q<bundler>, [">= 1.1.0"])
|
72
|
-
s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
|
73
|
-
s.add_dependency(%q<simplecov>, [">= 0"])
|
74
|
-
s.add_dependency(%q<rb-fsevent>, [">= 0"])
|
75
|
-
s.add_dependency(%q<guard>, ["~> 1.1.1"])
|
76
|
-
s.add_dependency(%q<guard-rspec>, ["~> 1.0.0"])
|
77
|
-
s.add_dependency(%q<growl>, [">= 0"])
|
78
|
-
s.add_dependency(%q<debugger>, [">= 0"])
|
79
|
-
end
|
80
|
-
else
|
81
|
-
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
82
|
-
s.add_dependency(%q<rspec>, ["~> 2.10.0"])
|
83
|
-
s.add_dependency(%q<bundler>, [">= 1.1.0"])
|
84
|
-
s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
|
85
|
-
s.add_dependency(%q<simplecov>, [">= 0"])
|
86
|
-
s.add_dependency(%q<rb-fsevent>, [">= 0"])
|
87
|
-
s.add_dependency(%q<guard>, ["~> 1.1.1"])
|
88
|
-
s.add_dependency(%q<guard-rspec>, ["~> 1.0.0"])
|
89
|
-
s.add_dependency(%q<growl>, [">= 0"])
|
90
|
-
s.add_dependency(%q<debugger>, [">= 0"])
|
91
|
-
end
|
18
|
+
gem.add_dependency('workers', ['0.0.6'])
|
92
19
|
end
|
93
|
-
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tribe
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,207 +9,46 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-01-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
15
|
+
name: workers
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
|
-
- -
|
19
|
+
- - '='
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
22
|
-
type: :
|
21
|
+
version: 0.0.6
|
22
|
+
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
26
26
|
requirements:
|
27
|
-
- -
|
27
|
+
- - '='
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
none: false
|
34
|
-
requirements:
|
35
|
-
- - ~>
|
36
|
-
- !ruby/object:Gem::Version
|
37
|
-
version: 2.10.0
|
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: 2.10.0
|
46
|
-
- !ruby/object:Gem::Dependency
|
47
|
-
name: bundler
|
48
|
-
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
|
-
requirements:
|
51
|
-
- - ! '>='
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version: 1.1.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: 1.1.0
|
62
|
-
- !ruby/object:Gem::Dependency
|
63
|
-
name: jeweler
|
64
|
-
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
|
-
requirements:
|
67
|
-
- - ~>
|
68
|
-
- !ruby/object:Gem::Version
|
69
|
-
version: 1.8.3
|
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: 1.8.3
|
78
|
-
- !ruby/object:Gem::Dependency
|
79
|
-
name: simplecov
|
80
|
-
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
|
-
requirements:
|
83
|
-
- - ! '>='
|
84
|
-
- !ruby/object:Gem::Version
|
85
|
-
version: '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: '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'
|
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'
|
110
|
-
- !ruby/object:Gem::Dependency
|
111
|
-
name: guard
|
112
|
-
requirement: !ruby/object:Gem::Requirement
|
113
|
-
none: false
|
114
|
-
requirements:
|
115
|
-
- - ~>
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: 1.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.1
|
126
|
-
- !ruby/object:Gem::Dependency
|
127
|
-
name: guard-rspec
|
128
|
-
requirement: !ruby/object:Gem::Requirement
|
129
|
-
none: false
|
130
|
-
requirements:
|
131
|
-
- - ~>
|
132
|
-
- !ruby/object:Gem::Version
|
133
|
-
version: 1.0.0
|
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: 1.0.0
|
142
|
-
- !ruby/object:Gem::Dependency
|
143
|
-
name: growl
|
144
|
-
requirement: !ruby/object:Gem::Requirement
|
145
|
-
none: false
|
146
|
-
requirements:
|
147
|
-
- - ! '>='
|
148
|
-
- !ruby/object:Gem::Version
|
149
|
-
version: '0'
|
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'
|
158
|
-
- !ruby/object:Gem::Dependency
|
159
|
-
name: debugger
|
160
|
-
requirement: !ruby/object:Gem::Requirement
|
161
|
-
none: false
|
162
|
-
requirements:
|
163
|
-
- - ! '>='
|
164
|
-
- !ruby/object:Gem::Version
|
165
|
-
version: '0'
|
166
|
-
type: :development
|
167
|
-
prerelease: false
|
168
|
-
version_requirements: !ruby/object:Gem::Requirement
|
169
|
-
none: false
|
170
|
-
requirements:
|
171
|
-
- - ! '>='
|
172
|
-
- !ruby/object:Gem::Version
|
173
|
-
version: '0'
|
174
|
-
description: Actor Model for Ruby. Can support millions of actors (limited by memory).
|
175
|
-
Currently experimental and not recommended for production.
|
176
|
-
email: chad@remesch.com
|
29
|
+
version: 0.0.6
|
30
|
+
description: Event driven actors for Ruby
|
31
|
+
email:
|
32
|
+
- chad@remesch.com
|
177
33
|
executables: []
|
178
34
|
extensions: []
|
179
|
-
extra_rdoc_files:
|
180
|
-
- LICENSE.txt
|
181
|
-
- README.rdoc
|
35
|
+
extra_rdoc_files: []
|
182
36
|
files:
|
183
|
-
- .
|
184
|
-
- .rspec
|
37
|
+
- .gitignore
|
185
38
|
- Gemfile
|
186
39
|
- Gemfile.lock
|
187
|
-
-
|
188
|
-
-
|
189
|
-
- README.rdoc
|
40
|
+
- LICENSE
|
41
|
+
- README.md
|
190
42
|
- Rakefile
|
191
|
-
- VERSION
|
192
43
|
- lib/tribe.rb
|
193
44
|
- lib/tribe/actor.rb
|
194
|
-
- lib/tribe/
|
45
|
+
- lib/tribe/dedicated_actor.rb
|
195
46
|
- lib/tribe/mailbox.rb
|
196
|
-
- lib/tribe/message.rb
|
197
47
|
- lib/tribe/registry.rb
|
198
|
-
- lib/tribe/
|
199
|
-
- lib/tribe/thread_pool.rb
|
200
|
-
- lib/tribe/timer.rb
|
201
|
-
- lib/tribe/worker.rb
|
202
|
-
- spec/lib/tribe/actor_spec.rb
|
203
|
-
- spec/lib/tribe/dispatcher_spec.rb
|
204
|
-
- spec/lib/tribe/registry_spec.rb
|
205
|
-
- spec/lib/tribe/scheduler_spec.rb
|
206
|
-
- spec/lib/tribe/timer_spec.rb
|
207
|
-
- spec/lib/tribe/worker_spec.rb
|
208
|
-
- spec/spec_helper.rb
|
48
|
+
- lib/tribe/version.rb
|
209
49
|
- tribe.gemspec
|
210
|
-
homepage:
|
211
|
-
licenses:
|
212
|
-
- MIT
|
50
|
+
homepage: ''
|
51
|
+
licenses: []
|
213
52
|
post_install_message:
|
214
53
|
rdoc_options: []
|
215
54
|
require_paths:
|
@@ -222,17 +61,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
222
61
|
version: '0'
|
223
62
|
segments:
|
224
63
|
- 0
|
225
|
-
hash:
|
64
|
+
hash: 2679671106278227985
|
226
65
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
227
66
|
none: false
|
228
67
|
requirements:
|
229
68
|
- - ! '>='
|
230
69
|
- !ruby/object:Gem::Version
|
231
70
|
version: '0'
|
71
|
+
segments:
|
72
|
+
- 0
|
73
|
+
hash: 2679671106278227985
|
232
74
|
requirements: []
|
233
75
|
rubyforge_project:
|
234
|
-
rubygems_version: 1.8.
|
76
|
+
rubygems_version: 1.8.24
|
235
77
|
signing_key:
|
236
78
|
specification_version: 3
|
237
|
-
summary:
|
79
|
+
summary: Event driven actors for Ruby designed for high performance.
|
238
80
|
test_files: []
|
data/.document
DELETED
data/.rspec
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
--color
|
data/Guardfile
DELETED
data/README.rdoc
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
= tribe
|
2
|
-
|
3
|
-
Actor Model for Ruby. Currently experimental and not recommend for production. Many standard features of the Actor Model are missing.
|
4
|
-
|
5
|
-
== Contributing to tribe
|
6
|
-
|
7
|
-
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
8
|
-
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
9
|
-
* Fork the project.
|
10
|
-
* Start a feature/bugfix branch.
|
11
|
-
* Commit and push until you are happy with your contribution.
|
12
|
-
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
-
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
-
|
15
|
-
== Copyright
|
16
|
-
|
17
|
-
Copyright (c) 2012 Chad Remesch. See LICENSE.txt for
|
18
|
-
further details.
|
19
|
-
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.0.3
|
data/lib/tribe/dispatcher.rb
DELETED
data/lib/tribe/message.rb
DELETED
data/lib/tribe/scheduler.rb
DELETED
@@ -1,78 +0,0 @@
|
|
1
|
-
module Tribe
|
2
|
-
class Scheduler
|
3
|
-
FREQUENCY = 100 # Hz.
|
4
|
-
|
5
|
-
def initialize(options = {})
|
6
|
-
@frequency = options[:frequency] || FREQUENCY
|
7
|
-
@run = true
|
8
|
-
@timers = SortedSet.new
|
9
|
-
@messages = Queue.new
|
10
|
-
@thread = Thread.new { main }
|
11
|
-
end
|
12
|
-
|
13
|
-
def shutdown
|
14
|
-
message = { :command => :shutdown }
|
15
|
-
@messages.push(message)
|
16
|
-
|
17
|
-
@thread.join
|
18
|
-
end
|
19
|
-
|
20
|
-
def schedule(timer)
|
21
|
-
message = { :command => :schedule, :timer => timer }
|
22
|
-
@messages.push(message)
|
23
|
-
|
24
|
-
true
|
25
|
-
end
|
26
|
-
|
27
|
-
def unschedule(timer)
|
28
|
-
message = { :command => :unschedule, :timer => timer }
|
29
|
-
@messages.push(message)
|
30
|
-
|
31
|
-
true
|
32
|
-
end
|
33
|
-
|
34
|
-
private
|
35
|
-
def main
|
36
|
-
sleep_val = 1.0 / @frequency
|
37
|
-
|
38
|
-
while @run
|
39
|
-
sleep(sleep_val)
|
40
|
-
process_commands
|
41
|
-
fire_timers
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def process_commands
|
46
|
-
@messages.length.times do
|
47
|
-
message = @messages.pop
|
48
|
-
|
49
|
-
case message[:command]
|
50
|
-
when :schedule
|
51
|
-
@timers.add(message[:timer])
|
52
|
-
when :unschedule
|
53
|
-
@timers.delete(message[:timer])
|
54
|
-
when :shutdown
|
55
|
-
@run = false
|
56
|
-
else
|
57
|
-
raise("Invalid command: #{message[:command]}")
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
def fire_timers
|
63
|
-
count = 0
|
64
|
-
|
65
|
-
while true
|
66
|
-
return 0 if @timers.empty?
|
67
|
-
|
68
|
-
if (timer = @timers.first).send(:fire?)
|
69
|
-
@timers.delete(timer)
|
70
|
-
timer.send(:fire)
|
71
|
-
count += 1
|
72
|
-
else
|
73
|
-
return count
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
data/lib/tribe/thread_pool.rb
DELETED
@@ -1,58 +0,0 @@
|
|
1
|
-
module Tribe
|
2
|
-
class ThreadPool
|
3
|
-
THREAD_COUNT = 64
|
4
|
-
|
5
|
-
def initialize(options = {})
|
6
|
-
@count = options[:count] || THREAD_COUNT
|
7
|
-
|
8
|
-
@threads = []
|
9
|
-
@lock = Mutex.new
|
10
|
-
@queue = Queue.new
|
11
|
-
|
12
|
-
spawn(@count)
|
13
|
-
end
|
14
|
-
|
15
|
-
def dispatch(&block)
|
16
|
-
@queue.push({ :command => :perform, :task => block })
|
17
|
-
|
18
|
-
true
|
19
|
-
end
|
20
|
-
|
21
|
-
def shutdown
|
22
|
-
@lock.synchronize do
|
23
|
-
@count.times do
|
24
|
-
@queue.push({ :command => :shutdown })
|
25
|
-
end
|
26
|
-
|
27
|
-
@threads.each { |thread| thread.join }
|
28
|
-
|
29
|
-
true
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
private
|
34
|
-
def spawn(count)
|
35
|
-
count.times do
|
36
|
-
@lock.synchronize do
|
37
|
-
thread = Thread.new { thread_main }
|
38
|
-
@threads.push(thread)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def thread_main
|
44
|
-
while (message = @queue.pop)
|
45
|
-
case message[:command]
|
46
|
-
when :perform
|
47
|
-
begin
|
48
|
-
message[:task].call
|
49
|
-
rescue Exception => e
|
50
|
-
puts "Worker caught exception: #{e.message}\n#{e.backtrace.join("\n")}"
|
51
|
-
end
|
52
|
-
when :shutdown
|
53
|
-
return
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
data/lib/tribe/timer.rb
DELETED
@@ -1,51 +0,0 @@
|
|
1
|
-
module Tribe
|
2
|
-
class Timer
|
3
|
-
attr_reader :fire_at
|
4
|
-
attr_reader :repeat
|
5
|
-
|
6
|
-
def initialize(seconds, options = {}, &block)
|
7
|
-
@seconds = seconds.to_f
|
8
|
-
@callback = block
|
9
|
-
@scheduler = options[:scheduler] || Tribe.scheduler
|
10
|
-
@repeat = options[:repeat] || false
|
11
|
-
|
12
|
-
schedule
|
13
|
-
end
|
14
|
-
|
15
|
-
def cancel
|
16
|
-
@scheduler.unschedule(self)
|
17
|
-
end
|
18
|
-
|
19
|
-
def <=>(timer)
|
20
|
-
if self.object_id == timer.object_id
|
21
|
-
return 0
|
22
|
-
else
|
23
|
-
return self.fire_at <=> timer.fire_at
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
private
|
28
|
-
def fire?(current_time = nil)
|
29
|
-
current_time ||= now
|
30
|
-
|
31
|
-
now >= @fire_at
|
32
|
-
end
|
33
|
-
|
34
|
-
def fire
|
35
|
-
@callback.call
|
36
|
-
rescue Exception => e
|
37
|
-
puts "Timer caught exception: #{e.message}\n#{e.backtrace.join("\n")}"
|
38
|
-
ensure
|
39
|
-
schedule if @repeat
|
40
|
-
end
|
41
|
-
|
42
|
-
def now
|
43
|
-
Time.now.to_f
|
44
|
-
end
|
45
|
-
|
46
|
-
def schedule
|
47
|
-
@fire_at = now + @seconds
|
48
|
-
@scheduler.schedule(self)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
data/lib/tribe/worker.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
module Tribe
|
2
|
-
class Worker
|
3
|
-
def initialize(queue, options = {})
|
4
|
-
@queue = queue
|
5
|
-
@thread = Thread.new { main }
|
6
|
-
end
|
7
|
-
|
8
|
-
def join
|
9
|
-
@thread.join
|
10
|
-
end
|
11
|
-
|
12
|
-
private
|
13
|
-
def main
|
14
|
-
while (message = @queue.pop)
|
15
|
-
case message[:command]
|
16
|
-
when :shutdown
|
17
|
-
return
|
18
|
-
when :perform
|
19
|
-
begin
|
20
|
-
message[:task].call
|
21
|
-
rescue Exception => e
|
22
|
-
puts "Worker caught exception: #{e.message}\n#{e.backtrace.join("\n")}"
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|