allq 0.3.5 → 0.3.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/allq/actions/base.rb +11 -3
- data/lib/allq/actions/bury.rb +1 -1
- data/lib/allq/actions/delete.rb +1 -1
- data/lib/allq/actions/done.rb +1 -1
- data/lib/allq/actions/kick.rb +1 -1
- data/lib/allq/actions/release.rb +1 -1
- data/lib/allq/actions/stats.rb +1 -1
- data/lib/allq/actions/touch.rb +1 -1
- data/lib/allq/connection.rb +33 -14
- data/lib/allq/job.rb +0 -4
- data/lib/allq/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: 780c18967adea5a53a4b82b52b4af5ac6dbfe977
|
4
|
+
data.tar.gz: a079b08e7911d7b503169b2f90a4e513cec62738
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '07894d27ff1389c1db25779fe0c09253114df0db3e8c4587bbd25604f232f9a9fe944a30f7b5e38affdc11a451c6770bdd02ceb891bbe6a105df1a27de9c7ce8'
|
7
|
+
data.tar.gz: d8b782e4bbcdf622d6379836f0bda07396ed3d47c9126565d6283d04d9ce1e4a38a15c3615d4e5895293bc6798868fb1903e0fc824c1fe83048de0c652901ccd
|
data/lib/allq/actions/base.rb
CHANGED
@@ -24,13 +24,21 @@ class AllQ
|
|
24
24
|
data
|
25
25
|
end
|
26
26
|
|
27
|
-
def send_hash_as_json(data_hash)
|
27
|
+
def send_hash_as_json(data_hash, ignore_failure = false)
|
28
28
|
transmit_data = data_hash.to_json
|
29
29
|
result = nil
|
30
30
|
puts "transmitting data: #{transmit_data}" if ALLQ_DEBUG_DATA
|
31
|
-
|
32
|
-
|
31
|
+
if ignore_failure
|
32
|
+
@connection.socat(transmit_data) do |response|
|
33
|
+
result = response
|
34
|
+
end
|
35
|
+
results = "{}" if results.to_s == ""
|
36
|
+
else
|
37
|
+
@connection.transmit(transmit_data) do |response|
|
38
|
+
result = response
|
39
|
+
end
|
33
40
|
end
|
41
|
+
|
34
42
|
result
|
35
43
|
end
|
36
44
|
|
data/lib/allq/actions/bury.rb
CHANGED
data/lib/allq/actions/delete.rb
CHANGED
data/lib/allq/actions/done.rb
CHANGED
data/lib/allq/actions/kick.rb
CHANGED
data/lib/allq/actions/release.rb
CHANGED
@@ -5,7 +5,7 @@ class AllQ
|
|
5
5
|
job_id = data[:job_id]
|
6
6
|
delay = data[:delay] || 0
|
7
7
|
send_data = base_send(job_id, delay)
|
8
|
-
response = send_hash_as_json(send_data)
|
8
|
+
response = send_hash_as_json(send_data, true)
|
9
9
|
result = rcv(response)
|
10
10
|
return result["release"] && result["release"]["job_id"]
|
11
11
|
end
|
data/lib/allq/actions/stats.rb
CHANGED
data/lib/allq/actions/touch.rb
CHANGED
data/lib/allq/connection.rb
CHANGED
@@ -30,11 +30,28 @@ class AllQ
|
|
30
30
|
#
|
31
31
|
def initialize(address = '')
|
32
32
|
@address = address || _host_from_env
|
33
|
+
@mutex = Mutex.new
|
33
34
|
establish_connection
|
34
35
|
rescue
|
35
36
|
_raise_not_connected!
|
36
37
|
end
|
37
38
|
|
39
|
+
def socat(command, options={}, &block)
|
40
|
+
send_string = command.to_s
|
41
|
+
if send_string.include?("'")
|
42
|
+
puts "Single quotes not allow in JSON. This will probably error."
|
43
|
+
end
|
44
|
+
res = call_socat(send_string)
|
45
|
+
_raise_not_connected if res.include?("Connection refused")
|
46
|
+
yield block.call(res)
|
47
|
+
end
|
48
|
+
|
49
|
+
def call_socat(data)
|
50
|
+
cmd_string = "echo '#{data}' | socat - tcp4-connect:#{@address}"
|
51
|
+
output = `#{cmd_string}`
|
52
|
+
return output
|
53
|
+
end
|
54
|
+
|
38
55
|
# Send commands to allq server via connection.
|
39
56
|
#
|
40
57
|
# @param [String] command AllQ command
|
@@ -46,29 +63,25 @@ class AllQ
|
|
46
63
|
#
|
47
64
|
def transmit(command, options={}, &block)
|
48
65
|
_with_retry(options[:retry_interval], options[:init]) do
|
49
|
-
|
50
|
-
|
51
|
-
puts
|
66
|
+
@mutex.synchronize do
|
67
|
+
_raise_not_connected! unless @connection && !@connection.closed?
|
68
|
+
@connection.puts(command.to_s)
|
69
|
+
res = @connection.readline
|
70
|
+
yield block.call(res)
|
52
71
|
end
|
53
|
-
res = call_socat(send_string)
|
54
|
-
_raise_not_connected if res.include?("Connection refused")
|
55
|
-
yield block.call(res)
|
56
72
|
end
|
57
73
|
end
|
58
74
|
|
59
|
-
def call_socat(data)
|
60
|
-
cmd_string = "echo '#{data}' | socat - tcp4-connect:#{address}"
|
61
|
-
output = `#{cmd_string}`
|
62
|
-
return output
|
63
|
-
end
|
64
|
-
|
65
75
|
# Close connection with allq server.
|
66
76
|
#
|
67
77
|
# @example
|
68
78
|
# @conn.close
|
69
79
|
#
|
70
80
|
def close
|
71
|
-
|
81
|
+
if @connection
|
82
|
+
@connection.close
|
83
|
+
@connection = nil
|
84
|
+
end
|
72
85
|
end
|
73
86
|
|
74
87
|
# Returns string representation of job.
|
@@ -77,7 +90,7 @@ class AllQ
|
|
77
90
|
# @conn.inspect
|
78
91
|
#
|
79
92
|
def to_s
|
80
|
-
"#<AllQ::Connection
|
93
|
+
"#<AllQ::Connection host=#{host.inspect} port=#{port.inspect}>"
|
81
94
|
end
|
82
95
|
alias :inspect :to_s
|
83
96
|
|
@@ -91,6 +104,11 @@ class AllQ
|
|
91
104
|
# establish_connection('localhost:3005')
|
92
105
|
#
|
93
106
|
def establish_connection
|
107
|
+
@address = address.first if address.is_a?(Array)
|
108
|
+
match = address.split(':')
|
109
|
+
@host, @port = match[0], Integer(match[1] || DEFAULT_PORT)
|
110
|
+
|
111
|
+
@connection = TCPSocket.new @host, @port
|
94
112
|
end
|
95
113
|
|
96
114
|
private
|
@@ -116,6 +134,7 @@ class AllQ
|
|
116
134
|
# @param [Integer] tries The maximum number of attempts to reconnect
|
117
135
|
def _reconnect(original_exception, retry_interval, tries=MAX_RETRIES)
|
118
136
|
close
|
137
|
+
establish_connection
|
119
138
|
rescue Errno::ECONNREFUSED
|
120
139
|
tries -= 1
|
121
140
|
if tries.zero?
|
data/lib/allq/job.rb
CHANGED
data/lib/allq/version.rb
CHANGED