job_reactor 0.5.1.beta2 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.markdown +3 -3
- data/lib/job_reactor/distributor.rb +10 -10
- data/lib/job_reactor/job_reactor.rb +14 -0
- metadata +5 -5
data/README.markdown
CHANGED
@@ -20,7 +20,7 @@ They will block the reactor and break normal processing.
|
|
20
20
|
|
21
21
|
If you can't divide 'THE BIG JOB' into 'small pieces' you shouldn't use JobReactor. See alternatives such [DelayedJob][4] or [Resque][1].
|
22
22
|
|
23
|
-
__JobReactor is the right solution if you have thousands, millions, and, we hope
|
23
|
+
__JobReactor is the right solution if you have thousands, millions, and, we hope, billions relatively small jobs.__
|
24
24
|
|
25
25
|
Quick start
|
26
26
|
===========
|
@@ -35,7 +35,7 @@ In your main application:
|
|
35
35
|
``` ruby
|
36
36
|
require 'job_reactor'
|
37
37
|
JR.run do
|
38
|
-
JR.start_distributor('localhost', 5000)
|
38
|
+
JR.start_distributor('localhost', 5000) #see documentation
|
39
39
|
end
|
40
40
|
sleep(1) until(JR.ready?)
|
41
41
|
|
@@ -64,7 +64,7 @@ JR.run! do
|
|
64
64
|
:name => 'worker_1',
|
65
65
|
:server => ['localhost', 5001],
|
66
66
|
:distributors => [['localhost', 5000]]
|
67
|
-
})
|
67
|
+
}) #see documentation
|
68
68
|
end
|
69
69
|
```
|
70
70
|
Run 'application.rb' in one terminal window and 'worker.rb' in another.
|
@@ -5,16 +5,15 @@ module JobReactor
|
|
5
5
|
module Distributor
|
6
6
|
extend self
|
7
7
|
|
8
|
-
# Gets nodes
|
9
8
|
# You can monitor available nodes connections in you application.
|
10
|
-
# For example
|
11
|
-
# EM::PeriodicTimer.new(10) { JR::Logger.log nodes}
|
9
|
+
# For example:
|
10
|
+
# EM::PeriodicTimer.new(10) { JR::Logger.log nodes}.
|
12
11
|
#
|
13
12
|
def nodes
|
14
13
|
@@nodes ||= []
|
15
14
|
end
|
16
15
|
|
17
|
-
# Contains connections pool - all node connections
|
16
|
+
# Contains connections pool - all node connections.
|
18
17
|
#
|
19
18
|
def connections
|
20
19
|
@@connections ||= []
|
@@ -24,7 +23,8 @@ module JobReactor
|
|
24
23
|
@@connect_to || "#{@@host}:#{@@port}"
|
25
24
|
end
|
26
25
|
|
27
|
-
#Starts distributor on given hast and port
|
26
|
+
# Starts distributor on given hast and port.
|
27
|
+
# See JR.start_distributor documentation.
|
28
28
|
#
|
29
29
|
def start(host, port, opts = {})
|
30
30
|
@@connect_to = opts[:connect_to] && opts[:connect_to].join(':')
|
@@ -34,9 +34,9 @@ module JobReactor
|
|
34
34
|
EM.start_server(host, port, JobReactor::Distributor::Server)
|
35
35
|
end
|
36
36
|
|
37
|
-
# Tries to find available node connection
|
38
|
-
# If it is distributor will send marshalled data
|
39
|
-
# If get_connection returns nil distributor will try again after 1 second
|
37
|
+
# Tries to find available node connection.
|
38
|
+
# If it is distributor will send marshalled data.
|
39
|
+
# If get_connection returns nil distributor will try again after 1 second.
|
40
40
|
#
|
41
41
|
def send_data_to_node(hash)
|
42
42
|
connection = get_connection(hash)
|
@@ -56,8 +56,8 @@ module JobReactor
|
|
56
56
|
|
57
57
|
# Looks for available connection.
|
58
58
|
# If job hash specified node, tries check if the node is available.
|
59
|
-
# If not, returns nil or tries to find any other free node if :always_use_specified_node == true
|
60
|
-
# If job hasn't any specified node, methods return any available connection or nil (and will be launched again in one second)
|
59
|
+
# If not, returns nil or tries to find any other free node if :always_use_specified_node == true.
|
60
|
+
# If job hasn't any specified node, methods return any available connection or nil (and will be launched again in one second).
|
61
61
|
#
|
62
62
|
def get_connection(hash)
|
63
63
|
if hash['node']
|
@@ -39,6 +39,14 @@ module JobReactor
|
|
39
39
|
# Parses jobs.
|
40
40
|
# Requires storage.
|
41
41
|
# Creates and start node.
|
42
|
+
# Options are:
|
43
|
+
# :storage - now available: 'memory_storage' and 'redis_storage';
|
44
|
+
# :name - uniq node name like 'my_favorite_memory_node';
|
45
|
+
# :server - address where node server starts (example: ['123.123.123.123', 1234];
|
46
|
+
# :distributors - address or addresses of distributor(s) node will try to connect (example: [['111.111.111.111', 5000], ['localhost', 5001]]);
|
47
|
+
# :connect_to - use this option if you have different ip-address to access your machine from outside world. Example (connect_to: ['213.122.132.231', 8000]).
|
48
|
+
# If you specify :connect_to option the connected distributor will use this host and port to connect the node.
|
49
|
+
# If not, distributor will use host and port from :server option.
|
42
50
|
#
|
43
51
|
def start_node(opts)
|
44
52
|
parse_jobs
|
@@ -47,6 +55,12 @@ module JobReactor
|
|
47
55
|
node.start
|
48
56
|
end
|
49
57
|
|
58
|
+
# Starts distributor server on given host and port.
|
59
|
+
# If you have different ip-address to access your machine from outside world use additional option :connect_to.
|
60
|
+
# For example:
|
61
|
+
# JR.start_distributor('0.0.0.0', 5000, connect_to: ['123,223,234,213', 5000]).
|
62
|
+
# So the node will use '123,223,234,213:5000' to send the 'feedbacks' to distributor
|
63
|
+
#
|
50
64
|
def start_distributor(host, port, opts = {})
|
51
65
|
JR::Distributor.start(host, port, opts)
|
52
66
|
end
|
metadata
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: job_reactor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.1
|
5
|
-
prerelease:
|
4
|
+
version: 0.5.1
|
5
|
+
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Anton Mishchuk
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-06-
|
13
|
+
date: 2012-06-18 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: eventmachine
|
@@ -100,9 +100,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
100
100
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
101
|
none: false
|
102
102
|
requirements:
|
103
|
-
- - ! '
|
103
|
+
- - ! '>='
|
104
104
|
- !ruby/object:Gem::Version
|
105
|
-
version:
|
105
|
+
version: '0'
|
106
106
|
requirements: []
|
107
107
|
rubyforge_project:
|
108
108
|
rubygems_version: 1.8.24
|