job_reactor 0.5.0 → 0.5.1.beta1
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 +6 -8
- data/lib/job_reactor/distributor.rb +7 -9
- data/lib/job_reactor/job_reactor.rb +3 -3
- data/lib/job_reactor/logger.rb +1 -1
- data/lib/job_reactor/node.rb +5 -1
- data/lib/job_reactor/node/client.rb +1 -1
- metadata +5 -5
data/README.markdown
CHANGED
@@ -1,11 +1,9 @@
|
|
1
|
-
JobReactor
|
1
|
+
JobReactor <img src='https://secure.travis-ci.org/antonmi/job_reactor.png'>
|
2
2
|
==========
|
3
|
-
Now we are in beta (need to complete documentation and fix some bugs)
|
4
|
-
---------------------------------------------------
|
5
3
|
|
6
4
|
JobReactor is a library for creating, scheduling and processing background jobs.
|
7
5
|
It is asynchronous client-server distributed system based on [EventMachine][0].
|
8
|
-
Inspired by [Resque][1], [Beanstalkd][2]([Stalker][3]), [DelayedJob][4], and etc.
|
6
|
+
Inspired by [Resque][1], [Beanstalkd][2] ([Stalker][3]), [DelayedJob][4], and etc.
|
9
7
|
|
10
8
|
JobReactor has not 'rails' integration for the time being.
|
11
9
|
But it is very close. We need to test the system with different servers (clusters) and automate the initialization and re-start processes.
|
@@ -26,10 +24,10 @@ __JobReactor is the right solution if you have thousands, millions, and, we hope
|
|
26
24
|
|
27
25
|
Quick start
|
28
26
|
===========
|
29
|
-
|
27
|
+
```gem install job_reactor```
|
30
28
|
|
31
|
-
|
32
|
-
|
29
|
+
__You should install [Redis][5] if you want to persist your jobs.__
|
30
|
+
```$ sudo apt-get install redis-server```
|
33
31
|
|
34
32
|
In your main application:
|
35
33
|
`application.rb`
|
@@ -46,7 +44,7 @@ loop do
|
|
46
44
|
JR.enqueue 'my_job', {arg1: 'Hello'}
|
47
45
|
end
|
48
46
|
```
|
49
|
-
Define the 'my_job' in separate directory (files with job's definitions must be in separate directory):
|
47
|
+
Define the 'my_job' in separate directory (files with job's definitions **must** be in separate directory):
|
50
48
|
`reactor_jobs/my_jobs.rb`
|
51
49
|
``` ruby
|
52
50
|
include JobReactor
|
@@ -5,14 +5,6 @@ module JobReactor
|
|
5
5
|
module Distributor
|
6
6
|
extend self
|
7
7
|
|
8
|
-
def host
|
9
|
-
@@host
|
10
|
-
end
|
11
|
-
|
12
|
-
def port
|
13
|
-
@@port
|
14
|
-
end
|
15
|
-
|
16
8
|
# Gets nodes
|
17
9
|
# You can monitor available nodes connections in you application.
|
18
10
|
# For example
|
@@ -28,9 +20,14 @@ module JobReactor
|
|
28
20
|
@@connections ||= []
|
29
21
|
end
|
30
22
|
|
23
|
+
def server
|
24
|
+
@@connect_to || "#{@@host}:#{@@port}"
|
25
|
+
end
|
26
|
+
|
31
27
|
#Starts distributor on given hast and port
|
32
28
|
#
|
33
|
-
def start(host, port)
|
29
|
+
def start(host, port, opts = {})
|
30
|
+
@@connect_to = opts[:connect_to] && opts[:connect_to].join(':')
|
34
31
|
@@host = host
|
35
32
|
@@port = port
|
36
33
|
JR::Logger.log "Distributor listens #{host}:#{port}"
|
@@ -47,6 +44,7 @@ module JobReactor
|
|
47
44
|
data = Marshal.dump(hash)
|
48
45
|
connection.send_data(data)
|
49
46
|
connection.lock
|
47
|
+
JR::Logger.log "Distributor sent job '#{hash['name']}' to '#{connection.name}'"
|
50
48
|
else
|
51
49
|
EM.next_tick do
|
52
50
|
send_data_to_node(hash)
|
@@ -105,7 +105,7 @@ module JobReactor
|
|
105
105
|
hash.merge!('node' => opts[:node]) if opts[:node]
|
106
106
|
hash.merge!('not_node' => opts[:not_node]) if opts[:not_node]
|
107
107
|
|
108
|
-
hash.merge!('distributor' =>
|
108
|
+
hash.merge!('distributor' => JR::Distributor.server)
|
109
109
|
|
110
110
|
add_succ_feedbacks!(hash, success_proc) if success_proc.is_a? Proc
|
111
111
|
add_err_feedbacks!(hash, error_proc) if error_proc.is_a? Proc
|
@@ -184,7 +184,7 @@ module JobReactor
|
|
184
184
|
# Adds success callback which will launch when node reports success
|
185
185
|
#
|
186
186
|
def add_succ_feedbacks!(hash, callback)
|
187
|
-
distributor =
|
187
|
+
distributor = JR::Distributor.server
|
188
188
|
feedback_id = "#{distributor}_#{Time.now.utc.to_f}"
|
189
189
|
succ_feedbacks.merge!(feedback_id => callback)
|
190
190
|
hash.merge!('on_success' => feedback_id)
|
@@ -193,7 +193,7 @@ module JobReactor
|
|
193
193
|
# Adds error callback which will launch when node reports error
|
194
194
|
#
|
195
195
|
def add_err_feedbacks!(hash, errback)
|
196
|
-
distributor =
|
196
|
+
distributor = JR::Distributor.server
|
197
197
|
feedback_id = "#{distributor}_#{Time.now.utc.to_f}"
|
198
198
|
err_feedbacks.merge!(feedback_id => errback)
|
199
199
|
hash.merge!('on_error' => feedback_id)
|
data/lib/job_reactor/logger.rb
CHANGED
data/lib/job_reactor/node.rb
CHANGED
@@ -4,7 +4,7 @@ module JobReactor
|
|
4
4
|
class Node
|
5
5
|
|
6
6
|
def initialize(opts)
|
7
|
-
@config = { storage: opts[:storage], name: opts[:name], server: opts[:server], distributors: opts[:distributors]}
|
7
|
+
@config = { storage: opts[:storage], name: opts[:name], server: opts[:server], connect_to: opts[:connect_to], distributors: opts[:distributors]}
|
8
8
|
end
|
9
9
|
|
10
10
|
def config
|
@@ -25,6 +25,10 @@ module JobReactor
|
|
25
25
|
@connections ||= {}
|
26
26
|
end
|
27
27
|
|
28
|
+
def server
|
29
|
+
config[:connect_to] || config[:server]
|
30
|
+
end
|
31
|
+
|
28
32
|
# Retrying jobs if any,
|
29
33
|
# starts server and tries to connect to distributors.
|
30
34
|
#
|
@@ -35,7 +35,7 @@ module JobReactor
|
|
35
35
|
#
|
36
36
|
def connection_completed
|
37
37
|
JR::Logger.log('Begin distributor handshake')
|
38
|
-
data = {node_info: {name: @node.config[:name], server: @node.
|
38
|
+
data = {node_info: {name: @node.config[:name], server: @node.server} }
|
39
39
|
data = Marshal.dump(data)
|
40
40
|
send_data(data)
|
41
41
|
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.
|
5
|
-
prerelease:
|
4
|
+
version: 0.5.1.beta1
|
5
|
+
prerelease: 6
|
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-15 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: 1.3.1
|
106
106
|
requirements: []
|
107
107
|
rubyforge_project:
|
108
108
|
rubygems_version: 1.8.24
|