pthread 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pthread/pthread.rb +22 -22
- data/lib/pthread/pthread_executor.rb +3 -3
- data/lib/pthread/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ab2e480b2458075f38532a9e4d66ed2432e71402
|
4
|
+
data.tar.gz: ab4a5edef41900153124ffa68173570b3d713e53
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c431e34a38e3c2007c8ca1e5ed96d09d43ad5c0bc21af3b2f0b188181b4a58bcb472b4b478771d7093af2a834d24a0830b5b3e5b314ab0f3b59862da4642e03a
|
7
|
+
data.tar.gz: 0f7c4a73d6274c2a15cd4c7034d7c86a2fd7012213be9e9647cfa7aec1d7cb3cb13afe607dbecdd2cbec2ce9b3ee1313d4ec40f533d43cf61955059ec3cc6bec
|
data/lib/pthread/pthread.rb
CHANGED
@@ -4,15 +4,15 @@ module Pthread
|
|
4
4
|
|
5
5
|
# The +Pthread+ class is the main class that users work with.
|
6
6
|
# It used for creating forks to be executed in a separate processes
|
7
|
-
# including
|
7
|
+
# including on remote machines.
|
8
8
|
class Pthread
|
9
9
|
|
10
10
|
@@ts = Rinda::TupleSpace.new
|
11
11
|
@@pids = []
|
12
12
|
|
13
|
-
# Starts the drb server
|
13
|
+
# Starts the drb server.
|
14
14
|
#
|
15
|
-
# @param [
|
15
|
+
# @param [String] host that contains host url and port.
|
16
16
|
#
|
17
17
|
# @example Start service
|
18
18
|
# Pthread::Pthread.start_service '192.168.1.100:12345'
|
@@ -21,16 +21,15 @@ module Pthread
|
|
21
21
|
DRb.start_service("druby://#{@@host}", @@ts)
|
22
22
|
end
|
23
23
|
|
24
|
-
# Adds executors on the same machine as the main programm
|
24
|
+
# Adds executors on the same machine as the main programm.
|
25
25
|
#
|
26
|
-
# @param [
|
27
|
-
# @param [
|
26
|
+
# @param [FixNum] count amount of executors to start.
|
27
|
+
# @param [Symbol, String] queue name of the queue for executors to be attached to.
|
28
28
|
#
|
29
29
|
# @example Add executors without a queue
|
30
30
|
# Pthread::Pthread.add_executors 5
|
31
31
|
# @example Add executors for specific queue
|
32
32
|
# Pthread::Pthread.add_executors 5, :tasks
|
33
|
-
|
34
33
|
def self.add_executors(count = 1, queue=nil)
|
35
34
|
count.times do
|
36
35
|
@@pids << fork do
|
@@ -40,19 +39,19 @@ module Pthread
|
|
40
39
|
end
|
41
40
|
end
|
42
41
|
|
43
|
-
# Adds a single executor on the same machine as the main programm
|
42
|
+
# Adds a single executor on the same machine as the main programm.
|
44
43
|
#
|
45
|
-
# @param [
|
44
|
+
# @param [Symbol, String] queue name of the queue for executor to be attached to.
|
46
45
|
#
|
47
|
-
# @example Add executor without a queue
|
46
|
+
# @example Add an executor without a queue
|
48
47
|
# Pthread::Pthread.add_executor
|
49
|
-
# @example Add executor for specific queue
|
48
|
+
# @example Add an executor for a specific queue
|
50
49
|
# Pthread::Pthread.add_executor, :tasks
|
51
50
|
def self.add_executor(queue=nil)
|
52
51
|
add_executors(1, queue)
|
53
52
|
end
|
54
53
|
|
55
|
-
# Kills all launched executors on this machine
|
54
|
+
# Kills all launched executors on this machine.
|
56
55
|
#
|
57
56
|
# @example Add executors without a queue
|
58
57
|
# Pthread::Pthread.kill_executors
|
@@ -61,9 +60,9 @@ module Pthread
|
|
61
60
|
@@pids = []
|
62
61
|
end
|
63
62
|
|
64
|
-
# Initializes new pthread and schedules execution of the job
|
63
|
+
# Initializes new pthread and schedules execution of the job.
|
65
64
|
#
|
66
|
-
# @param [
|
65
|
+
# @param [Hash] job should contain :code, :context and optionally :queue
|
67
66
|
#
|
68
67
|
# @example Initialize new parrallel job
|
69
68
|
# pthread = Pthread::Pthread.new queue: 'tasks', code: %{
|
@@ -74,25 +73,26 @@ module Pthread
|
|
74
73
|
end
|
75
74
|
|
76
75
|
|
77
|
-
# Returns value of a pthread
|
76
|
+
# Returns value of a pthread.
|
78
77
|
#
|
79
|
-
# @note If value
|
80
|
-
# @note If pthread resulted in an exception it will be raised
|
78
|
+
# @note If value is not yet calculated it will block the execution.
|
79
|
+
# @note If pthread resulted in an exception it will be raised.
|
81
80
|
#
|
82
|
-
# @example
|
81
|
+
# @example
|
82
|
+
# pthread.value
|
83
83
|
#
|
84
|
-
# @return [
|
84
|
+
# @return [Object] value of a pthread.
|
85
85
|
def value
|
86
86
|
raw_value.is_a?(StandardError) ? raise(raw_value) : raw_value
|
87
87
|
end
|
88
88
|
|
89
89
|
private
|
90
90
|
|
91
|
-
# Returns raw value of a pthread even if it was an exception
|
91
|
+
# Returns raw value of a pthread even if it was an exception.
|
92
92
|
#
|
93
|
-
# @note If value
|
93
|
+
# @note If value is not yet calculated will block the execution.
|
94
94
|
#
|
95
|
-
# @return [
|
95
|
+
# @return [Object] raw value of a pthread.
|
96
96
|
def raw_value
|
97
97
|
@raw_value ||= @@ts.take([self.object_id, nil])[1]
|
98
98
|
end
|
@@ -8,10 +8,10 @@ module Pthread
|
|
8
8
|
|
9
9
|
# Initliazes new executor.
|
10
10
|
#
|
11
|
-
# @param [ String ] DRB host that has main programm running
|
12
|
-
# @param [ String, Symbol ] optinal queue name to attach executor
|
11
|
+
# @param [ String ] host DRB host that has main programm running.
|
12
|
+
# @param [ String, Symbol ] queue optinal queue name to attach executor.
|
13
13
|
#
|
14
|
-
# @example Connect to remote
|
14
|
+
# @example Connect to remote dRb service
|
15
15
|
# Pthread::PthreadExecutor.new '192.168.1.100:12345', :tasks
|
16
16
|
def initialize(host, queue=nil)
|
17
17
|
DRb.start_service
|
data/lib/pthread/version.rb
CHANGED